Ios UNNotificationCategory子类初始化问题
我想将Ios UNNotificationCategory子类初始化问题,ios,swift,apple-push-notifications,usernotifications,convenience-methods,Ios,Swift,Apple Push Notifications,Usernotifications,Convenience Methods,我想将UNNotificationCategory(UserNotifications)子类化,因为我想使用枚举而不是硬编码字符串作为类别标识符。 UNNotificationCategorydefinition中有一个便利init public convenience init(identifier: String, actions: [UNNotificationAction], intentIdentifiers: [String], options: UNNotificationCate
UNNotificationCategory
(UserNotifications)子类化,因为我想使用枚举而不是硬编码字符串作为类别标识符。
UNNotificationCategory
definition中有一个便利init
public convenience init(identifier: String, actions: [UNNotificationAction], intentIdentifiers: [String], options: UNNotificationCategoryOptions = [])
我无法为我的子类编写初始值设定项。
我知道我不能在子类中指定初始值设定项,因为我想调用超类的便利init。但我的便利init也抛出了编译器错误
代码如下:
enum PushNotificationCategoryIdentifier:String {
}
convenience init(categoryIdentifier:PushNotificationCategoryIdentifier, actions:[UNNotificationAction], intentIdentifiers:[String], options: UNNotificationCategoryOptions) {
self.init(identifier: categoryIdentifier.rawValue, actions: actions, intentIdentifiers: intentIdentifiers, options: options)
}
这将导致错误:self.init在从初始值设定项返回之前不会在所有路径上调用
我猜这是因为这个类是在Objective-C中实现的,可能他们没有从便利初始化器调用指定的初始化器(因为Objective-C类不必从便利初始化器调用指定的初始化器)
但这是否意味着如果我想在其中编写初始值设定项,就不能将
UNNotificationCategory
子类化?不,您可以这样做。您必须为此定义init()
方法。现在您只定义了便利初始化()
。但是您必须在子类中定义init()
。
当您编写便利init()
时,它只是以一种简单的方式帮助初始化,但您仍然必须使用便利init()
中的语法init()
调用指定的init。
你可以在上阅读。不,你可以这样做。您必须为此定义
init()
方法。现在您只定义了便利初始化()
。但是您必须在子类中定义init()
。
当您编写便利init()
时,它只是以一种简单的方式帮助初始化,但您仍然必须使用便利init()
中的语法init()
调用指定的init。
你可以在用什么定义init上阅读它?我无法初始化UNNotificationCategory变量,因为所有变量都是仅获取属性。用什么定义init?我无法初始化UNNotificationCategory变量,因为所有变量都是仅获取属性。