ios - Bolts Framework的使用方法[Facebook+Parse]

标签 ios facebook parse-platform bolts-framework

刚才我看到this announcement来自 Facebook 关于 IOS 的 Bolts Framework

我可以将其视为主要概念:

The first component in Bolts is “tasks”, which make organization of complex asynchronous code more manageable

但是我没有得到这个。我对 Bolts 框架 感到困惑。如何使用它(是否与网络服务相关或与 JSON 响应解析相关)。

他们提供了带有解析 SDK 的 ParseObject 示例,但我不知道,他们没有提供任何 Xcode 项目示例。

Facebook 提供 explanation对这个。但是我不知道如何与我的项目集成。

他们提供的代码非常困惑:

[[object saveAsync:obj] continueWithBlock:^id(BFTask *task) {
  if (task.isCancelled) {
    // the save was cancelled.
  } else if (task.error) {
    // the save failed.
  } else {
    // the object was saved successfully.
    SaveResult *saveResult = task.result;
  }
  return nil;
}];

我们可以下载bolts-framework here .任何人都可以解释一下吗?

更新: Here我收到了一些关于 bolt 新问题的答案。

示例: 假设你想从 AssertLibrary 加载所有图像,并在加载时将所有图像调整为标准大小,所以如果使用主线程,它会被击中。在这个地方,如果你采用异步操作方式,BFTask 怎么用呢?另一个例子。有一次,您试图通过异步操作并行调用 10 个 Web 服务,您如何将 GCD 与 BFTask 一起使用?

最佳答案

bolt 很棒。同意文档现在有点不集中。不过,这是一个简单的例子:

// the completion source is the *source* of the task...
BFTaskCompletionSource *source = [BFTaskCompletionSource taskCompletionSource];
[self asynchronousMethodWithCompletion:^(id response, NSError *error) {
   // your task completed; inform the completion source, which handles
   // the *completion* of the task
   error ? [source setError:error] : [source setResult:entity];
}];

[source.task continueWithBlock:^id(BFTask *task) {
   // this will be executed after the asynchronous task completes...
}];

我发现它对组完成(半伪代码)特别有用:

NSMutableArray *tasks = @[].mutableCopy;
loop {
  BFTaskCompletionSource *source = [BFTaskCompletionSource taskCompletionSource];

  // ...make a task similar to above...

  [tasks addObject:source.task];
}

// now the group completion:
BFTask *groupTask = [BFTask taskForCompletionOfAllTasks:tasks.copy];
[source.task continueWithBlock:^id(BFTask *task) {
   // this will be executed after *all* the group tasks have completed
}];

这是一种更简洁的方式来执行您可能使用调度组执行的操作。不过,在以串行和并行方式对任务进行排序等方面,它还有很多其他内容。

希望对您有所帮助。

关于ios - Bolts Framework的使用方法[Facebook+Parse],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21521570/

相关文章:

facebook - 发送通知

iOS FBRequest成功委托(delegate)方法

javascript - 更新 parse.com 中的用户对象

iOS Delegate 以防止无效输入

iphone - 界面生成器 : Choose media based on target

ios - 对齐自定义绘图中的文本

ios - 当项目具有动态大小时,如何在 Collection View 中有单个水平行的项目?

javascript - Facebook Javascript SDK : Error validating access token when posting to feed

ios - 解析.com : Pass an array of dictionaries to backgroundJob through httprequest

javascript - 保存后设置解析对象属性