作为以下文件
UILocalNotification.userInfo
说:
您可以将任意键值对添加到此字典。但是,键和值必须有效
property-list types
; 如果没有,则引发异常。
您需要自己将数据转换为这种类型。您可能想这样做:
enum Keys {
static let title = "title"
static let uuid = "uuid"
static let startDate = "startDate"
static let endDate = "endDate"
}
extension MeetingData {
func dictionaryRepresentation() -> NSDictionary {
return [Keys.title: title,
Keys.uuid: uuid,
Keys.startDate: startDate,
Keys.endDate: endDate]
}
init?(dictionaryRepresentation dict: NSDictionary) {
if let title = dict[Keys.title] as? String,
let uuid = dict[Keys.uuid] as? String,
let startDate = dict[Keys.startDate] as? NSDate,
let endDate = dict[Keys.endDate] as? NSDate
{
self.init(title: title, uuid: uuid, startDate: startDate, endDate: endDate)
} else {
return nil
}
}
}
然后你可以使用
myData.dictionaryRepresentation()
转换为字典,以及
MeetingData(dictionaryRepresentation: ...)
从字典中转换。