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

dispatch_once_t is unavailable in Swift 3 #1056

Closed
johnantoni opened this issue Oct 17, 2016 · 3 comments
Closed

dispatch_once_t is unavailable in Swift 3 #1056

johnantoni opened this issue Oct 17, 2016 · 3 comments

Comments

@johnantoni
Copy link
Contributor

johnantoni commented Oct 17, 2016

Hi, now dispatch_once_t is unavailable in Swift 3 how would you recommend replacing it?

XCode suggests using lazily initialized globals, what would be a recommended replacement?

    override class func initialize() {
        struct Static {
            static var onceToken : dispatch_once_t = 0;
        }
        dispatch_once(&Static.onceToken) {
            self.registerSubclass()
        }
    }

Now looking at this post http://stackoverflow.com/questions/33069650/parse-com-subclassing-in-swift-2 it suggests registering the SubClass within AppDelegate:

Appdelegate.swift
....
Foobar.registerSubclass()

So if I register the subclass in AppDelegate do I even need to include the initialize block inside the subclass? removing the problem with dispatch_once.

What do you think or is this crazy?

Appreciate it,

@johnantoni
Copy link
Contributor Author

johnantoni commented Oct 19, 2016

Actually looking through the previous releases I found that in the Parse SDK 1.14.0 all subclasses are registered automatically

https://github.com/ParsePlatform/Parse-SDK-iOS-OSX/releases/tag/1.14.0

So we don't need to do the call inside AppDelegate to .registerSubClass and coincidentally we don't need to do the call inside the SubClass via the initialize method above, which means we don't need to use the dispatch_once method to make sure it's only ever registered once, removing the Swift 3 code compatibility issue.

So problem solved.

Closing this issue, please re-open if needed.

@johnantoni
Copy link
Contributor Author

johnantoni commented Oct 22, 2016

Turns out you still need to register the subClass in AppDelegate otherwise it cannot identify your class.

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        ....
        Parse.initialize(with: configuration)
        Foobar.registerSubclass()
        return true
    }

@johnantoni
Copy link
Contributor Author

Final problem I had was not storing PFUser.currentUser() in between close/reopen, thought it was due to removing initialize but not the case thank god.

Just have to enable KeyChain Sharing in your app capabilities.

#1038

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

1 participant