PromiseKitiOS 異步開(kāi)發(fā)
現(xiàn)代化的開(kāi)發(fā)都要求高度異步,iOS 開(kāi)發(fā)也是一樣,PromiseKit 能提供強(qiáng)大的 iOS 開(kāi)發(fā)異步功能,非常容易使用。
PromiseKit 不僅僅是 Promises 的實(shí)現(xiàn),還是輔助函數(shù)的集合,使得 iOS 開(kāi)發(fā)典型的異步模式更強(qiáng)大。
PromiseKit 支持集成到其他 Cocoapods,如果用戶的庫(kù)有異步操作,而又喜歡使用 PromiseKit,則可以添加了一個(gè)可選的缺省子說(shuō)明書,提供 Promises 服務(wù),文檔會(huì)幫助集成 PromiseKit 到用戶自身的 pods 中。
示例:
[CLLocationManager promise].catch(^{
return self.chicagoLocation;}).then(^(CLLocation *loc){
return [NSURLConnection GET:@"http://user.net/%f/%f", loc.latitude, loc.longitude];}).then(^(NSDictionary *user){
UIAlertView *alert = [UIAlertView new];
alert.title = [NSString stringWithFormat:@"Hi, %@!", user.name];
[alert addButtonWithTitle:@"Bye"];
[alert addButtonWithTitle:@"Hi!"];
return alert.promise;}).then(^(NSNumber *tappedButtonIndex, UIAlertView *alert){
if (tappedButtonIndex.intValue == alert.cancelButtonIndex)
return nil;
id vc = [HelloViewController new]
return [self promiseViewController:vc animated:YES completion:nil].then(^(id resultFromViewController){
//…
});}).catch(^(NSError *err){
//…});
評(píng)論
圖片
表情
