Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //test func
- func encodeTest<T>(object: T) where T: Encodable {
- // The object should be AnyObject which conforms to Encodable.
- let encoder = JSONEncoder()
- if let _ = try? encoder.encode(object) {
- print("encode success.")
- // I need fix the json here.
- }
- }
- class Test: Encodable {
- var a = "a"
- var b = "b"
- }
- //test1
- var t: Test?
- t = Test()
- // it is ok.
- encodeTest(object: t)
- //test2
- if let tf = t as Encodable? {
- // Cannot invoke 'encodeTest' with an argument list of type '(object: Encodable)'
- encodeTest(object: tf)
- }
Add Comment
Please, Sign In to add comment