ios swift init of uninitialized instance variable -
ios swift init of uninitialized instance variable -
have simple question on swift. have simple base of operations class base of operations , kid class abase:
class base of operations { var test1:int init(fortest test1:int) { self.test1 = test1 } } class abase : base of operations { var test3:int init(foranother test3:int) { **super.init(fortest: test3)** self.test3 = test3 } } i compiler error @ super.init(fortest: test3) line in init phone call in abase. error is:
property 'self.test3' no initialized @ super.init call.
i'm trying understand why can't init object uninitialized var in swift?
swift has two-phase init, in need initialize of members before doing else.
init(foranother test3:int) { self.test3 = test3 super.init(fortest: test3) } more info here:
https://developer.apple.com/library/prerelease/ios/documentation/swift/conceptual/swift_programming_language/initialization.html
search two-phase init on page.
if needed phone call super.init() (for example, if test3 depended on did), give initial value test3 in declaration.
ios swift init
Comments
Post a Comment