utahiosmac / Marshal

Marshaling the typeless wild west of [String: Any]
MIT License
697 stars 62 forks source link

Change definition of `MarshaledObject` to `[String: Any]`? #32

Closed brianmullen closed 8 years ago

brianmullen commented 8 years ago

@bwhiteley @jarsen (and anyone else that wants to chime in)

We have been talking about making the core of this library generic. I just realized that we cant store native Swift data types (Int8, Int16, Int32, Int64, UInt, etc) since the values of MarshaledObject have to be AnyObject (which means all of our number extractions need to be adjusted to always pull values out of an NSNumber).

I have been thinking about how we might get data from any source. So, thinking along those line we also need to evaluate how we convert basic data types from one data type to another. Parsing JSON with odd formats might benefit from this, for example, a service might wrap some integer as a string and so instead of having the consumer pull out a string and then cast it as an integer, we could make use of the builtin data type conversions and do that for them automatically. This way the only time a consumer needs to do something like that is in those odd/rare cases.

I have been working on some initial code (attached) that would convert it over but I don't want to go too far until we have discussed it. I have passing unit tests written up as well and have tested it on mac and iOS (both 32bit & 64bit) for all data types. We would still need to adjust some additional code, for example the array extraction doesn't work if the values are Any.

What do you think? ValueType.swift.zip

brianmullen commented 8 years ago

Here are my unit tests (assuming you change the definition). MarshaledObjectTests.swift.zip

jarsen commented 8 years ago

I've been thinking a little about this over the weekend after merging in your PR that added support for a bunch of values. I actually wonder if we do want to support every single data type; the number of extensions is really starting to proliferate. I'm half of the opinion that maybe we only support the basics, and if someone wants Int8 or the likes then they write their own extension.

brianmullen commented 8 years ago

Either way if we want to truly support Swift data types like Int8 through a user extension (or our own extension) we would still need to change the definition.

brianmullen commented 8 years ago

I am closing this issue as implementing this will add complexity and that goes against the goal of this being a simple and easy to understand library.