initialization - Why do I have to override my init in Swift now? -


import foundation  class student: nsobject {     var name: string     var year: int     var major: string     var gpa : string      init(name:string, year:int, major:string, gpa:string)     {         self.name = name         self.year = year         self.major = major         self.gpa = gpa     }      convenience init()     {         //calls longer init method written above     } } 

--

the error shows atthe line of convenience init

overriding declaration requires 'override' keyword

i've tried googling , reading guides on initializers in swift, seems able make initializers fine without overriding anything.

it looks convenience initializer empty why error. example if change to:

convenience init() {     self.init(name: "", year: 0, major: "nothing", gpa: "4.0") } 

the error go away.

i wonder why set student inherit nsobject. doesn't necessary class.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -