UILocalNotification userinfo中的Swift Dictionary

And*_*ath 3 xcode dictionary ios uilocalnotification swift

我不明白为什么当我尝试设置UILocalNotification的userinfo字典时,XCode返回错误"'@lvalue $ T7'与(NSObject,AnyObject)'"不同.这是样本:

var medicine: String?
var notification = UILocalNotification()
notification.userInfo["medicine"] = medicine
Run Code Online (Sandbox Code Playgroud)

这不是我第一次遇到字典问题.我不明白苹果用xcode 6 beta 3改变了什么.

我尝试过很多演员,但我无法理解这是什么问题.

mat*_*att 12

您正在创建一个新的UILocalNotification,因此它userInfo是零; 那里什么都没有.userInfo如果要将其视为Swift字典(正如您尝试的那样),则必须创建一些明确的Swift字典类型.此外,您需要一个实际值medicine,而不仅仅是未初始化的类型.例如:

var userInfo = [String:String]()
let medicine = "SomeMedicine"
userInfo["medicine"] = medicine
notification.userInfo = userInfo
Run Code Online (Sandbox Code Playgroud)