Storing structures with reference type properties #46
NSExceptional
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The JSON object mapping library I've been working on is finally complete enough that I've started using it to replace Codable in another project of mine. I've just run into this issue when running my old tests though: arrays are not copied safely. I think this also means I'm not properly storing any struct (and enum!) with reference type properties.
Right now, I use this extension to create instances of custom struct types:
Basically, I retain things that are objects and do a bitwise copy of every value for each key. I'm not sure what's going on below, the debugger just looks crazy. I'm guessing the array storage is being released since I'm not doing any manual retains for reference-type keys of structures—
Person
is a struct here.After being constructed
After being copied (passed to a function)
Trying to print the array yields this:
I'm guessing I just need to do manual retains of reference type keys of custom structs. That seems like a lot of work though, is there anything in the runtime that can do this for me? Or is there a flag in the metadata that tells me when I need to do it so I can avoid enumerating the keys of every single struct type? Etc
Beta Was this translation helpful? Give feedback.
All reactions