How can you convert a struct to json. Like Stringify in javascript?
Following gives the error: Argument type 'MyStruct' does not conform to expected type 'AnyType.
I get that, but how would you do it?
struct MyStruct{
var name: String
}
let obj = MyStruct(name: "Bob")
let data = try NSJSONSerialization.dataWithJSONObject(obj, options: .PrettyPrinted)
if let string = NSString(data: data, encoding: NSUTF8StringEncoding){
print(string)
}