Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tribute to Mantle

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

Tribute to Mantle

As Swift getting matured and Mantle will not be maintained for Swift, I put this presentation as a tribute for one library that I use quite often when producing MVP.

Avatar for Sergio Utama

Sergio Utama

November 23, 2015

More Decks by Sergio Utama

Other Decks in Programming

Transcript

  1. Mantle - Pros It simplify JSON parsing and mapping Fully

    support NSCoding & NSCopying Extensible Archivable (NSKeyedArchiever or NSManagedObject)
  2. JSON MAPPING @interface GHIssue : MTLModel <MTLJSONSerializing> // your .m

    file . . . + (NSDictionary *)JSONKeyPathsByPropertyKey { return @{ @"propertyName": @"key_from_api" }; } . . .
  3. JSON MAPPING - CUSTOM // your .m file . .

    . + (NSValueTransformer *)propertyNameJSONTransformer { return [NSValueTransformer valueTransformerForName:MTLURLValueTransformerName]; } . . .
  4. EXTEND YOUR CLASS // your class which extend from class

    that implement MTLJSONSerializing // your .m file . . . + (NSDictionary *)JSONKeyPathsByPropertyKey { return [super.JSONKeyPathsByPropertyKey mtl_dictionaryByAddingEntriesFromDictionary: @{ @"propertyName": @“key_from_api" } ]; } . . .
  5. ARCHIVE - NSManagedObject @interface GHIssue : MTLModel < MTLManagedObjectSerializing >

    // your .m file . . . + (NSString *)managedObjectEntityName { return @"YourEntityName"; } + (NSDictionary *)managedObjectKeysByPropertyKey { return @{ @"managedObjectProperty" : @"yourProperty" }; } . . .
  6. ARCHIVE - NSManagedObject @interface GHIssue : MTLModel < MTLManagedObjectSerializing >

    // your .m file . . . + (NSSet *)propertyKeysForManagedObjectUniquing { return [NSSet setWithObject:@"uniqueProperty"]; } + (NSDictionary *)relationshipModelClassesByPropertyKey { return @{ @"propertyThatContainOtherObject": Song.class, }; } . . .
  7. Mantle - Cons It fetch all - No partial fetch

    It use lot of memory (if you have large data set and fetch it all at once)