How to make PAPreferences support Swift?
I want inherit one swift class from PAPreferences, but don't know how to deal with @dymamic
class MUSPreferences : PAPreferences
{
@dynamic var firstVersionInstalled:String
@dynamic var latestVersionInstalled:String
...
}
cause the init method in PAPreferences. will dynamic assign all value from NSUserDefault to the property, so I don't need to set them in the MUSPreferences's init(), but if I don't set them, xcode will report error "Property xxx not intiialized at super.init call", Do you have some solution to deal with this problem?
Currently (as of Beta 5), although the Swift language has a dynamic modifier, it's not correctly marking the property as dynamic in the sense that Obj-C expects. Because of this, Swift dynamic properties don't work.
The short-term workaround is to simply have a PAPreferences subclass written in Objective-C and use that from Swift.
Once the Swift runtime settles down a bit, I'll investigate directly compatibility again.
Thanks!
class MUSPreferences : PAPreferences
{
dynamic var firstVersionInstalled:String?
dynamic var extensionIntraEmphasis:Bool = false
init()
{
super.init()
let version = NSBundle.mainBundle().infoDictionary["CFBundleVersion"] as AnyObject! as String
self.firstVersionInstalled = version
}
}
Now, I workaround with set the type with "?" or give it a default value, just make it build ok,