2

Has anyone tried using the Parse Framework with swift yet? As long as you add a bridge-file you can work with both swift and objective-c code.

Here is my query.. the 'objects' array returned from Parse has all my data properly, but the method is returning before setting the 'results' array to the 'objects' array, so i keep getting nothing back from the function. Perhaps Parse will need to receive an update to support swift, or did I possibly make a mistake somewhere? Thanks

   class func fetchAllCategories() -> NSArray {

        var results : NSArray = NSArray()

        var query : PFQuery = PFQuery(className: "Category")
        query.findObjectsInBackgroundWithBlock({(NSArray objects, NSError error) in
            if (error != nil) {
                NSLog("error " + error.localizedDescription)
            }
            else {
                NSLog("objects %@", objects as NSArray)
                results = NSArray(array: objects)
            }
        })

        NSLog("results %@", results)

        return results
    }

1 Answer 1

2

This has nothing to do with Swift. query.findObjectsInBackgroundWithBlock does the work in the background so it's going to finish much later, after the function returns.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh your right. I will fix it by just reloading the table view inside the block instead of calling a method. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.