yonaskolb / SwagGen

OpenAPI/Swagger 3.0 Parser and Swift code generator
MIT License
626 stars 146 forks source link

Avoid '??' has non-optional type warning #207

Closed marcuswu0814 closed 4 years ago

marcuswu0814 commented 4 years ago

螢幕快照 2019-12-03 下午7 16 39

yonaskolb commented 4 years ago

True, something must of gotten change in a refactor. Feel free to update with a PR!

marcuswu0814 commented 4 years ago

Just forgot to run test, I will fix it ASAP. 😃

yonaskolb commented 4 years ago

Whoops sorry, I thought this was an issue as I viewed it through the new github notification interface. This is already a PR! :)

marcuswu0814 commented 4 years ago

螢幕快照 2019-12-03 下午8 16 21

I have no idea why the compiler say it must be unwrapped when try to build test specs. 😅

yonaskolb commented 4 years ago

I think it's because of the double optional, though not sure of the specifics. Try a 2 step process

...
let jsonValue = try? JSONSerialization.jsonObject(with: jsonData),
let jsonDictionary = jsonValue as? [String: Any] else {
...
marcuswu0814 commented 4 years ago

I try to change the guard condition to:

 let jsonDictionary = (try? JSONSerialization.jsonObject(with: jsonData)) as? [String: Any] 

the error gone, any suggestion to update the template?

yonaskolb commented 4 years ago

Yep, the parenthesis will work too

marcuswu0814 commented 4 years ago

Which one did you prefer? I can fix that.

yonaskolb commented 4 years ago

I don't mind, I'll let you choose :)