泛型使我的解码函数抛出错误

时间:2018-05-19 06:42:34

标签: json swift generics types

edges count: 4294967296
Before graph alloc free memory: 91485 MB
After graph alloc free memory: 91485 MB
After memset: 42236 MB
1 test: 23784 MB
2 test: 5280 MB
3 test: 490 MB
After actual load: 490 MB
After we removed the graph load: 49737 MB
After we closed the file: 49741 MB
Complete!
After we quit the function: 49741 MB

最初,我尝试使用do { let thing = try JSONDecoder().decode(LoginAndVerify.self, from: data ?? Data()) if thing is genericType { print("it is the type...") } print(genericType.Type.self) //simpleResponse = SimpleResponse(success: <#T##Int#>, message: <#T##String?#>, url: <#T##String?#>) print("WE DID IT") } catch let err { print("error: \(err.localizedDescription)") } ,但是发生了错误,我达到了decode(genericType.self。此代码打印line 10 "LoginAndVerify.type",但不打印line 6。这是为什么?如果编译器将line 4的类型识别为genericType,而LoginAndVerify.type的类型为thing,则不应该LoginAndVerify打印?为什么line 4不起作用?我错过了什么?

0 个答案:

没有答案