Rightpoint / RZImport

Automatic importing of data from NSDictionary to Cocoa objects
Other
18 stars 6 forks source link

Ignored keys #40

Open dostrander opened 8 years ago

dostrander commented 8 years ago

Add the ability to specify keys NOT to import

jvisenti commented 8 years ago

@dostrander Is + (RZNonnull RZIStringArray *)rzi_ignoredKeys; not what you're looking for?

dostrander commented 8 years ago

Just for a specific import. In a similar context to this:

rzi_objectFromDictionary:(RZNonnull RZIStringDict *)dict withMappings:(RZNullable RZIKeyMap *)mappings;

So it'd be like rzi_objectFromDictionary:(RZNonnull RZIStringDict *)dict withMappings:(RZNullable RZIKeyMap *)mappings ignoredKeys: (RZIStringArray *);

@jvisenti

jvisenti commented 8 years ago

Why not just return NO from - (BOOL)rzi_shouldImportValue:(RZNonnull id)value forKey:(RZNonnull NSString *)key;, and simply not do anything for that key?

dostrander commented 8 years ago

In some scenarios I want to ignore, some scenarios I don't. Which the context of whether or not to ignore is from outside of the object (i.e. the viewController is telling whether or not a key should be ignored or not)

jvisenti commented 8 years ago

You could strip the key/value pairs you want to ignore from the dict before importing. That's what the suggested function would do internally anyway. Just not sure if the use case for this is large enough to warrant new API in the library. Seems like a category for "subtracting" two dicts at the call site would suffice, and then just pass in the result to the existing import function.

jvisenti commented 8 years ago

@dostrander How about

NSDictionary *importDict = :[fullDict removeObjectsForKeys:ignoredDict.allKeys];
[MyClass rzi_objectFromDictionaryimportDict]

?

dostrander commented 8 years ago

The problem is if it's an array of dictionaries, you have to iterate through just to remove the keys. Also it wouldn't break anything and would just be additive so not sure (as long as someone makes it) why it shouldn't go in.

dostrander commented 8 years ago

I probably shold have used the array example for the comment above ^^ :)

jvisenti commented 8 years ago

My only concern is that it makes the API more confusing. It adds an ignoredKeys parameter in addition to the existing static rzi_ignoredKeys and existing per-instance rzi_shouldImportValue:forKey:. At some point (probably already) the choice of static vs. instance vs. call site versions of these things is going to become confusing.

dostrander commented 8 years ago

I can get behind that. We should take a critical look at RZImport and see how it can be/ if it can be improved