異步函數的結果我有關於我的代碼的問題:返回結果等待iOS中
func isNotificationsEnabled()->Bool{
var isNotificationEnabled = false
center.getNotificationSettings() { (settings) in
switch settings.soundSetting{
case .enabled:
isNotificationEnabled = true
break
case .disabled:
isNotificationEnabled = false
break
case .notSupported:
isNotificationEnabled = false
break
}
}
return isNotificationEnabled
}
此函數的返回結果前center.getNotificationSettings()
。有沒有什麼辦法可以等待center.getNotificationSettings()
的結果並同步這個功能?
[在Swift函數中從異步調用返回數據]的可能的副本(http://stackoverflow.com/questions/25203556/returning-data-from-async-call-in-swift-功能) –
不要問,告訴!使用異步完成處理程序。 – vadian