Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UNNotificationCategory子类初始化问题_Ios_Swift_Apple Push Notifications_Usernotifications_Convenience Methods - Fatal编程技术网

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变量,因为所有变量都是仅获取属性。