var category:UIMutableUserNotificationCategory=UIMutableUserNotificationCategory()
category.identifier="DEFAULT_GATEGORY"
let defaultAction:NSArray=[action]
category.setActions(defaultAction as [AnyObject] as [AnyObject], forContext: UIUserNotificationActionContext.Minimal)
答案 0 :(得分:0)
假设action
的类型为UIUserNotificationAction
:
var category = UIMutableUserNotificationCategory() // NOTE: type not needed.
category.identifier = "DEFAULT_GATEGORY"
let defaultAction = [action] // NOTE: Type not needed.
category.setActions(defaultAction, forContext: UIUserNotificationActionContext.Minimal)
正如您所看到的,我所做的就是删除不需要的(和误导性的)类型信息。我发现依靠Swift的自动类型确定系统很有帮助。
使用以下Playground代码进行测试:
let action = UIMutableUserNotificationAction()
var category = UIMutableUserNotificationCategory()
category.identifier = "DEFAULT_GATEGORY"
let defaultAction = [action]
category.setActions(defaultAction, forContext: UIUserNotificationActionContext.Minimal)