In C++ we can use a member initialization list you initialize class member like:
object::object():_a(0), _b(0){}
Is there a way to do this same thing in swift(2.0)?
In C++ we can use a member initialization list you initialize class member like:
object::object():_a(0), _b(0){}
Is there a way to do this same thing in swift(2.0)?
For swift to require you to init class member means that the class member is an optionnal, you have to supply proper init in the class init. For example :
class PhAuthenticationToken : NSObject {
var authenticationToken : NSString
var expiry : NSDate?
var permissions : NSString
init(token : NSString, secondsToExpiry seconds : NSTimeInterval, permissions perms : NSString) {
self.authenticationToken = token
if (seconds != 0) {
self.expiry = NSDate(timeIntervalSinceNow: seconds)
}
self.permissions = perms
}
}
You should check the official documentation : https://developer.apple.com/library/mac/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html