My code.swift is below :
public class Test {
var testA: String = ""
var testB: String = ""
let T_testA : String = "testA"
let T_testB : String = "testB"
init(testA: String, testB: String) {
self.testA = testA
self.testB = testB
}
func toString() -> String? {
let jsonDic : [String: AnyObject] = [
T_testA: testA,
T_testB: testB,
]
do {
let jsonObject = try NSJSONSerialization.dataWithJSONObject( jsonDic, options: NSJSONWritingOptions.PrettyPrinted)
return String(data: jsonObject, encoding: NSUTF8StringEncoding)
} catch {
return nil
}
}
}
In my Tests.swift
func testPerformanceExample() {
let result1 = Test(testA: {"major": 1, "minor": 2}, testB: "http://google.com")
let result2 = result2.toString()!
print("result2=\n\(result2)")
}
I read similar case Here , It seems a different problem!
Is that possible to create the embedded json object together and return it as a String ?
testAis declared asString. How cantestAinTestsbe a dictionary?