Parse Framework with Swift

为君一笑 提交于 2019-12-11 02:07:41

问题


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:


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.



来源:https://stackoverflow.com/questions/24029510/parse-framework-with-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!