DBoyer
DBoyer

Reputation: 3122

Parse Framework with Swift

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
    }

Upvotes: 2

Views: 2529

Answers (1)

Jack Lawrence
Jack Lawrence

Reputation: 10772

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.

Upvotes: 2

Related Questions