微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PromiseKit iOS 异步开发

程序名称:PromiseKit

授权协议: MIT

操作系统: OS X

开发语言: Swift

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){
    //…});

PromiseKit 官网

http://promisekit.org/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐