Local variable d2 and data has the same type, but though d2 has two key value par, it is not getting assigned to data, why? Does @State makes it specific?
struct ContentView: View {
@State var data: [String: Any] = [String: Any]()
@State var res: ValidationResult?
init() {
updateValue()
return
}
func updateValue() {
do {
if let jsonURL = Bundle.main.url(forResource: "user", withExtension: "json") {
let jsonData = try Data(contentsOf: jsonURL)
guard let d2 = try JSONSerialization.jsonObject(with: jsonData, options: .mutableLeaves) as? [String: Any] else {
print("Can not convert to d2")
return
}
data = d2 // <-------