如何使用螺栓框架[Facebook + Parse]

Man*_*ani 9 facebook ios parse-platform bolts-framework

刚才我看到Facebook发布关于IOS 螺栓框架的这一消息.

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

Bolts中的第一个组件是"任务",它使复杂异步代码的组织更易于管理

但我没有得到这个.我很困惑Bolts framework.如何使用它(whether its related to web service or to JSON response parsing).

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

Facebook 就此提供了解释.但我无法弄清楚如何与我的项目集成.

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

[[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;
}];
Run Code Online (Sandbox Code Playgroud)

我们可以在这里下载bolt-framework .有人可以解释一下这个吗?

更新: 在这里我收到了一些关于螺栓新问题的答案.

示例: 假设您要加载AssertLibrary中的所有图像,并在加载时将所有图像的大小调整为标准大小,因此如果使用主线程,则会触发.在这个地方,如果你采用异步操作方式,如何使用BFTask呢?另一个例子.有一段时间,你试图用异步操作并行调用10个webservice,你怎么能在BFTask上使用GCD?

Jon*_*oke 11

螺栓很棒.同意文档现在有点不重要.这是一个简单的例子:

// 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...
}];
Run Code Online (Sandbox Code Playgroud)

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

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
}];
Run Code Online (Sandbox Code Playgroud)

这是一种更简洁的方式来执行您可能对调度组执行的操作.但是,在串行和并行等方面对任务进行排序等方面还有很多其他方面.

希望能帮助您入门.