我在等待**synchronously**
呼叫async
中心时遇到问题Facebook Graph API
。
var message: String? = ""
var error: ErrorType?
let dispatchGroup = dispatch_group_create()
dispatch_group_enter(dispatchGroup)
FacebookGraphAPI.getPostsWithCompletionHandler("[pageID]", parameters: ["limit": 1]) {
(posts, error) in
if error != nil {
error = ErrorType.Some
}
if posts == nil || posts!.count == 0 || !posts![0].createdTime.isToday {
error = ErrorType.Some
}
if error == nil {
message = posts![0].message
}
dispatch_group_leave(dispatchGroup)
}
dispatch_group_wait(dispatchGroup, DISPATCH_TIME_FOREVER)
if error != nil {
throw error!
}
return message
getPostsWithCompletionHandler 是我自己的函数,我知道它总是调用指定的处理程序。
请帮忙!