github-mantle

Mantle property class based on another property?

折月煮酒 提交于 2019-12-21 04:35:15
问题 How can I use Github Mantle to choose a property class based on another property in the same class? (or in the worse case another part of the JSON object). For example if i have an object like this: { "content": {"mention_text": "some text"}, "created_at": 1411750819000, "id": 600, "type": "mention" } I want to make a transformer like this: +(NSValueTransformer *)contentJSONTransformer { return [MTLValueTransformer transformerWithBlock:^id(NSDictionary* contentDict) { return [MTLJSONAdapter

Mantle convert 0 and 1 to BOOL automatically?

你离开我真会死。 提交于 2019-12-10 15:45:03
问题 Does Mantle already converts int values 0 and 1 in JSON to objective-C BOOL values? I have a model: @interface MyModel : MTLModel @property (nonatomic, readonly) BOOL isValid; @end And lets say JSON is: { is_valid: 0 } OR { is_valid: 1 } I want to know if Mantle would automatically convert is_valid into Objective-C BOOL value to do I have to explicity mention the following: + (NSValueTransformer)isValidJSONTransfermer { return [NSValueTransformer mtl_valueMappingTransformerWithDictionary:@{@

How to set default value in iOS Mantle model subclass

旧城冷巷雨未停 提交于 2019-12-08 18:46:37
问题 @interface Entity () @property (assign) int searchTotalPagesAll; @property (assign) int searchTotalPagesIdeas; @end @implementation Entity + (NSDictionary *)JSONKeyPathsByPropertyKey { return @{ @"Id": @"entity.id_entity", @"name": @"entity.name", @"coverage" : @"entity.coverage", @"id_city": @"entity.Id_City", @"cityName":@"entity.city", @"countryName":@"entity.country", @"stateName":@"entity.district", @"countryCode": @"entity.countrycode", @"keyword1": @"entity.key1", ... etc Since mantle

Transform NSString to NSURL within a JSON Array with Mantle

a 夏天 提交于 2019-12-07 12:06:58
问题 Let's say given to me is the following JSON response { "images": [ "http://domain.com/image1.jpg", "http://domain.com/image2.jpg", "http://domain.com/image3.jpg" ] } With Mantle I want to parse those strings and transform them into NSURLs but keep them in an NSArray. So my Objective-C model object would look like @interface MyModel : MTLModel <MTLJSONSerializing> // Contains NSURLs, no NSStrings @property (nonatomic, copy, readonly) NSArray *images; @end Is there an elegant way to achieve

Transform NSString to NSURL within a JSON Array with Mantle

◇◆丶佛笑我妖孽 提交于 2019-12-06 02:14:04
Let's say given to me is the following JSON response { "images": [ "http://domain.com/image1.jpg", "http://domain.com/image2.jpg", "http://domain.com/image3.jpg" ] } With Mantle I want to parse those strings and transform them into NSURLs but keep them in an NSArray. So my Objective-C model object would look like @interface MyModel : MTLModel <MTLJSONSerializing> // Contains NSURLs, no NSStrings @property (nonatomic, copy, readonly) NSArray *images; @end Is there an elegant way to achieve that? Some NSURL array transformer? + (NSValueTransformer*)imagesJSONTransformer { return

Mantle property class based on another property?

a 夏天 提交于 2019-12-03 14:47:27
How can I use Github Mantle to choose a property class based on another property in the same class? (or in the worse case another part of the JSON object). For example if i have an object like this: { "content": {"mention_text": "some text"}, "created_at": 1411750819000, "id": 600, "type": "mention" } I want to make a transformer like this: +(NSValueTransformer *)contentJSONTransformer { return [MTLValueTransformer transformerWithBlock:^id(NSDictionary* contentDict) { return [MTLJSONAdapter modelOfClass:ETMentionActivityContent.class fromJSONDictionary:contentDict error:nil]; }]; } But the

How to specify child objects type in an NSArray with Mantle

為{幸葍}努か 提交于 2019-12-03 04:14:28
问题 If I have a dictionary like { name: "Bob", cars: [ { make: "ford", year: "1972" }, { make: "mazda", year: "2000" } ], } and two models like: @interface CarModel : MTLModel @property (nonatomic, strong) NSString *make; @property (nonatomic, strong) NSString *year; @end @interface PersonModel : MTLModel @property (nonatomic, strong) NSString *name; @property (nonatomic, strong) NSArray *cars; @end How do I use Mantle so that my array of cars in my person model are CarModels? 回答1: Ah figured it

How to specify child objects type in an NSArray with Mantle

瘦欲@ 提交于 2019-12-02 17:32:15
If I have a dictionary like { name: "Bob", cars: [ { make: "ford", year: "1972" }, { make: "mazda", year: "2000" } ], } and two models like: @interface CarModel : MTLModel @property (nonatomic, strong) NSString *make; @property (nonatomic, strong) NSString *year; @end @interface PersonModel : MTLModel @property (nonatomic, strong) NSString *name; @property (nonatomic, strong) NSArray *cars; @end How do I use Mantle so that my array of cars in my person model are CarModels? Mr Rogers Ah figured it out. I needed to add a private method: + (NSValueTransformer *)carsTransformer { return