螺栓异步框架方法无法识别

Bolts async framework methods not recognized

在我的 swift iOS 应用程序中,我安装了螺栓框架,并在桥接头文件中得到了这个

#import <FacebookSDK/FacebookSDK.h>
#import <Parse/Parse.h>
#import <ParseFacebookUtils/PFFacebookUtils.h>
#import <Bolts/Bolts.h>

所以它应该有效。 但是,我无法访问此框架中的任何方法,例如 findAsync 或 continueWithSuccessBlock。他们不被认可。 我错过了重点吗?如何识别螺栓方法框架?

我随机发现语法与记录的所有内容不同。 文档指出要在查询时访问 BFTask,您必须键入:

var query = PFQuery(className:"Student")
findAsync(query).continueWithSuccessBlock

原来 "findAsync" 在我的版本中不存在?! 相反,我可以通过以下方式访问它:

query.findObjectsinBackground()

这个 returns 一个 BFTask,然后我可以访问其他 Bolts 代码,例如 continueWithBlock。

Bolts documentation 声明您需要自己实现 findAsync:。

For the examples in this doc, assume there are async versions of some common Parse methods, called saveAsync: and findAsync: which return a Task. In a later section, we'll show how to define these functions yourself.

您在 these examples 之后创建自己的 "Async" 函数。请注意本节的最后一句话:

It's similarly easy to create saveAsync:, findAsync: or deleteAsync:

这是 findAsync 的实现:

func findAsync(query:PFQuery) -> BFTask {
    var task = BFTaskCompletionSource()
    query.findObjectsInBackgroundWithBlock {
        (objects, error) -> Void in
        if error == nil {
            task.setResult(objects)
        } else {
            task.setError(error)
        }
    }
    return task.task
}