Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Why not add mappings for classes?</p> <pre><code>+ (NSDictionary *)mapClasses { return @{ @"category": [Category class], // ... }; } </code></pre> <p>For non-container properties, you could even do <a href="https://stackoverflow.com/questions/769319/how-to-detect-a-property-return-type-in-objective-c">runtime introspection of properties</a> to avoid redundant mappings.</p> <p>Container properties could map to special wrapper objects:</p> <pre><code>[OMContainer arrayWithClass:Key.class], @"keys", [OMContainer dicionaryWithKeyClass:ScopeID.class valueClass:Scope.class], @"possibleScopes", </code></pre> <p>Or even blocks for dynamic selection of types:</p> <pre><code>[OMDynamicType typeWithBlock:^(id obj){ if ([obj isKindOfClass:NSString.class] &amp;&amp; [obj hasPrefix:@"foo"]) return Foo.class; else return Bar.class; }], @"foo", </code></pre> <p>Implementing this could go something like:</p> <pre><code>+ (NSArray *)parseData:(NSData*)jsonData intoObjectsOfType:(Class)objectClass { NSArray *parsed = /* ... */ NSMutableArray *decoded = [NSMutableArray array]; for (id obj in parsed) { [decoded addObject:[self decodeRawObject:parsed intoObjectOfType:objectClass]]; } return decoded; } + (id)decodeRawObject:(NSDictionary *)dict intoObjectOfType:(Class)objectClass { // ... NSDictionary *jsonKeys = objectClass.mapProperties; NSDictionary *jsonClasses = objectClass.mapClasses; for (NSString *key in jsonKeys.allKeys) { NSString *objectProperty = jsonKeys[key]; NSString *value = dict[key]; if (value) { id klass = jsonClasses[key]; if (!klass) { [entity setValue:value forKey:objectProperty]; } else if (klass == klass.class) { [entity setValue:[self decodeRawObject:value intoObjectOfType:klass] forKey:objectProperty]; } else if (/* check for containers and blocks */) { // ... } } } // ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload