I am trying to create a dictionary extension where Dictionary is of the type <String, AnyObject>.
Was looking in many places and trying different approaches, but none of them seemed to work. This was one of them:
extension Dictionary where <String, AnyObject>{
var jsonString:String {
return ""
}
}
Another method that didn't actually work for some reason:
extension Dictionary where Key:Hashable, Value:AnyObject {
var jsonString:String {
do {
let stringData = try NSJSONSerialization.dataWithJSONObject(self, options: NSJSONWritingOptions.PrettyPrinted)
if let string = String(data: stringData, encoding: NSUTF8StringEncoding){
return string
}
}catch _ {
}
return ""
}
}
Got: Argument type 'Dictionary' does not conform to expected type of 'AnyObject'