I have a userInfo dictionary from UILocalNotification. Is there an easy way to get a String value when using implicit sweep?
if let s = userInfo?["ID"]
Gives me AnyObject, which I should pass to the string.
if let s = userInfo?["ID"] as String
Gives me an error about StringLiteralConvertable
It was just not necessary to declare two variables in order to get a string - one literal for a spread and another var for a cast line.
Edit
Here is my method. This also does not work - I get (NSObject, AnyObject) not converted to String in if statement.
for notification in scheduledNotifications { // optional chainging let userInfo = notification.userInfo if let id = userInfo?[ "ID" ] as? String { println( "Id found: " + id ) } else { println( "ID not found" ) } }
I do not have this in my question, but, besides this way to work, I would like to have
if let s = notification.userInfo?["ID"] as String
source share