aryaxt / OCMapper

Objective-C library to easily map NSDictionary to model objects, works perfectly with Alamofire. ObjectMapper works similar to GSON
MIT License
347 stars 45 forks source link

Usage #7

Closed coanag closed 10 years ago

coanag commented 10 years ago

I have an array and need to a need to map the indexpath.row dictionary to my preconfigured nsobject . Which files should I import to my project (from the ocmapper library)? Which the recommended method to configure the mapping? User *user = [User objectFromDictionary:aDictionary];?

aryaxt commented 10 years ago

OCMapper won't be able to map NSIndexPath for you. because row and sections are not properties. OCMapper can work for Objects (Model objects) that can be initialized by int method, and have properties.

You could always create a wrapper

[
   {
      "section" : 1,
      "row" :2
   },
   {
      "section" : 1,
      "row" :2
   },
   {
      "section" : 1,
      "row" :2
   }
]
@onterface IndexPath

@property(nonatomic, retain) NSNumber *row;
@property(nonatomic, retain) NSNumber *section;

@end
NSArray *indexPathList = [IndexPath objectFromDictionary:indexPathDictionary];

Then you can translate that to NSIndexPath

coanag commented 10 years ago

Great thanks, Which files from ocmapper should I import to my project?

aryaxt commented 10 years ago

Copy the whole source folder to your project. If you don't have Core Data referenced in your project remove these files to avoid compile errors

ManagedObjectInstanceProvider.m ManagedObjectInstanceProvider.h