这会将 UIUserNotificationType 数组分配给 UIUserNotificationType 变量。这不应该工作:
1)
var userNotificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
print(userNotificationTypes.dynamicType) // UIUserNotificationType
这是 [UIUserNotificationType] 的类型
2)
let intermidiate = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
print(intermidiate.dynamicType) // Array<UIUserNotificationType>
尝试分配它按预期失败:
3)
userNotificationTypes = intermidiate // Cannot assign a value of type '[UIUserNotificationType]' to a value of type 'UIUserNotificationType'
尝试分配[UIUserNotificationType]
显然UIUserNotificationType
是行不通的,那么为什么要1)
编译呢?