Open dostrander opened 8 years ago
@dostrander Is + (RZNonnull RZIStringArray *)rzi_ignoredKeys;
not what you're looking for?
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
Why not just return NO
from - (BOOL)rzi_shouldImportValue:(RZNonnull id)value forKey:(RZNonnull NSString *)key;
, and simply not do anything for that key?
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)
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.
@dostrander How about
NSDictionary *importDict = :[fullDict removeObjectsForKeys:ignoredDict.allKeys];
[MyClass rzi_objectFromDictionaryimportDict]
?
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.
I probably shold have used the array example for the comment above ^^ :)
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.
I can get behind that. We should take a critical look at RZImport and see how it can be/ if it can be improved
Add the ability to specify keys NOT to import