dispatch_group_wait 还没等

dispatch_group_wait not waiting

我无法等待 **synchronously**Facebook Graph APIasync 调用。

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 是我自己的函数,我知道它总是调用指定的处理程序。

请帮忙!

没关系,我通过放弃 Facebook SDK 并改用 contentsOfURL 函数解决了问题,因为它是同步的。