99热99这里只有精品6国产,亚洲中文字幕在线天天更新,在线观看亚洲精品国产福利片 ,久久久久综合网

歡迎加入QQ討論群258996829

Swift 執(zhí)行異步代碼框架 BrightFutures

發(fā)布時(shí)間:2016-08-23 22:10  回復(fù):0  查看:4530  感興趣:12  贊:0   最后回復(fù):2016-08-23 22:10  

Swift 執(zhí)行異步代碼框架 BrightFutures。

我們經(jīng)常會(huì)遇到寫(xiě)異步代碼的情況,比如在等待網(wǎng)絡(luò)響應(yīng)后更新UI,或者在要執(zhí)行耗時(shí)很長(zhǎng)的運(yùn)算后更新UI,通常我們會(huì)寫(xiě)類似下面的代碼:

User.logIn(username, password) { user, error in
    if !error {
        Posts.fetchPosts(user, success: { posts in
            // do something with the user's posts
        }, failure: handleError)
    } else {
        handleError(error) // handeError is a custom function to handle errors
    }
}

使用BrightFutures后,代碼將是這樣的

User.logIn(username,password).flatMap { user in
    Posts.fetchPosts(user)
}.onSuccess { posts in
    // do something with the user's posts
}.onFailure { error in
    // either logging in or fetching posts failed
}

相關(guān)開(kāi)源代碼

您還未登錄,請(qǐng)先登錄

熱門帖子

最新帖子

?