我想要子類UNNotificationCategory
(UserNotifications),因爲我想使用枚舉而不是硬編碼的字符串作爲類別標識符。 裏面有UNNotificationCategory
定義UNNotificationCategory子類初始化問題
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,並且可以它們沒有從稱爲方便initailizer指定initailizer(如Objective-C類不必須調用從便利initailizer指定初始化)。
但這是否意味着我不能繼承UNNotificationCategory
如果我想寫一個初始化器呢?
定義init用什麼?我不能初始化UNNotificationCategory變量,因爲所有都只有屬性。 –