iOS 異步開發:PromiseKit

jopen 10年前發布 | 55K 次閱讀 iOS開發 移動開發 PromiseKit

現代化的開發都要求高度異步,iOS 開發也是一樣,PromiseKit 能提供強大的 iOS 開發異步功能,非常容易使用。

PromiseKit 不僅僅是 Promises 的實現,還是輔助函數的集合,使得 iOS 開發典型的異步模式更強大。

PromiseKit 支持集成到其他 Cocoapods,如果用戶的庫有異步操作,而又喜歡使用 PromiseKit,則可以添加了一個可選的缺省子說明書,提供 Promises 服務,文檔會幫助集成 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){
    //…});

項目主頁:http://www.baiduhome.net/lib/view/home/1405958516882

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!