【发布时间】:2020-05-21 19:09:54
【问题描述】:
我正在尝试编写一个返回 Bool 的函数:
func registerForPushNotifications() -> (Bool) -> Void {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
[weak self] granted, error in
return { granted }
}
}
但我收到此错误:
Cannot convert return expression of type 'Void' to return type '(Bool) -> Void'
我做错了什么?
【问题讨论】:
-
1- 你的函数不返回
Bool,它返回一个以Bool为参数并返回Void的闭包。 2-return { granted }在定义为返回Void而不是Bool的闭包内调用。
标签: ios swift push-notification closures unusernotificationcenter