使用Swift解析框架 [英] Parse Framework with Swift

查看:109
本文介绍了使用Swift解析框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人尝试过使用Swift框架?只要添加一个桥文件,就可以使用swift和objective-c代码。

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.

这是我的查询..从Parse返回的'objects'数组正确地包含了我的所有数据,但是在将'results'数组设置为'之前返回了该方法对象的数组,所以我不断从函数中得到任何回报。也许Parse需要接收更新以支持swift,或者我可能在某处犯了错误?谢谢

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
    }


推荐答案

这与Swift无关。 query.findObjectsInBackgroundWithBlock 在后台工作,所以它会在函数返回后很晚完成。

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.

这篇关于使用Swift解析框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆