ObjectiveRecord
ObjectiveRecord copied to clipboard
Rethink mappings
I see a few issues with the way mappings are currently implemented:
- They are automatically, categorically added to all NSManagedObject classes.
- They are coupled to the NSManagedObject+ActiveRecord category.
- They are unidirectional (there's no way to cast local properties back into remote ones).
- They are declarative (and with @kattrali's #66, the dictionary can become quickly bloated).
- They do a lot by default (auto-camelizing, for example).
- They are a memory leak (we cache every unique remote key that we check for).
Let's explore ways to address these issues.
Proposal 1: Protocol-based Mappings
One thought is that we could provide a protocol, like NSCoding, that could be used to serialize/deserialize these mappings. E.g.,
@protocol ORCoding <NSObject>
+ (NSDictionary *)dictionaryFromRemoteDictionary:(NSDictionary)dict;
- (NSDictionary *)remoteDictionaryRepresentation;
@end
- One would have to manually opt-in to the protocol.
- Looser coupling, using
conformsToProtocol:. - It would enforce bidirectional mappings.
- Method logic is more imperative.
- It's not included by default, so there are no defaults.
- No memory leaks (that are our fault, anyway)!
Relates to #68.
/cc @supermarin
+1 That approach looks really nice
@stephencelis I think that makes sense