Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make PAPreferences support Swift? #6

Open
Fykec opened this issue Aug 4, 2014 · 2 comments
Open

How to make PAPreferences support Swift? #6

Fykec opened this issue Aug 4, 2014 · 2 comments

Comments

@Fykec
Copy link

Fykec commented Aug 4, 2014

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?

@dhennessy
Copy link
Owner

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.

@Fykec
Copy link
Author

Fykec commented Aug 5, 2014

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants