-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get struct out of GEOSwift.JSON #265
Comments
Hi @benpva16, thanks for sharing this use case. There are a few options here (some possible today, others that we'd need to build):
Let me know what you think! |
I figured out option 3 just before you commented. You have to re encode feature.properties["data"] back to JSON, then decode it to MyStruct. You can't do this directly, so you encode it then decode it back. let myStructData = feature.properties?["data"] ?? nil
let jsonData = try! JSONEncoder().encode(myStructData)
let decoder = JSONDecoder()
myStruct = try decoder.decode(MyStruct.self, from: jsonData) Obviously, it'd be more straight forward to be able to just say myStruct = try decoder.decode(MyStruct.self, from: feature.properties?["data"] ?? nil) or something similar. |
Mind if we leave this open? I'd like to explore adding a solution like what you described |
@macdrevx I don't mind at all, thank you for your consideration. If other solutions are added I would love to see what gets cooked up! |
I have a GEOSwift feature like this:
I want to retrieve the data member and put it into a struct that matches:
I can get the data, but the datatype is GEOSwift.JSON, and it's way too many properties to manually write all the code to do the conversion.
The text was updated successfully, but these errors were encountered: