Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshdholtz/protocol-ios
https://github.com/joshdholtz/protocol-ios
Last synced: 10 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/joshdholtz/protocol-ios
- Owner: joshdholtz
- Created: 2012-04-08T07:48:31.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-06-06T20:00:52.000Z (over 11 years ago)
- Last Synced: 2024-10-11T10:32:50.858Z (about 1 month ago)
- Language: Objective-C
- Homepage:
- Size: 133 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Protocol - Model Mapping Library for iOS
Protocol is a model mapping library that takes in a JSON string, NSDictionary, or NSArray, and maps it to ProtocolModel objects.##Benefits
- Map models within models
- Define custom functions for to be performed on values before mapping (ex: parse a NSString into an NSDate)### How to user a mapping
```objc
// Maps an NSDictionary to a UserModel
UserModel *user = [UserModel protocolModelWithDictionary:@{
@"id" : @1,
@"first_name" : @"Josh",
@"last_name" : @"Holtz"
}];
NSLog(@"User.userId - %@", user.userId);
NSLog(@"User.firstName - %@", user.firstName);
NSLog(@"User.lastName - %@", user.lastName);```
### Define mapping - UserMode.h
```objc
#import "ProtocolModel.h"@interface UserModel : ProtocolModel
@property (nonatomic, strong) NSNumber *userId;
@property (nonatomic, strong) NSString *firstName;
@property (nonatomic, strong) NSString *lastName;@end
```
### Define mapping - UserModel.m
```objc
#import "UserModel.h"@implementation UserModel
- (NSDictionary *)mapKeysToProperties {
return [[NSDictionary alloc] initWithObjectsAndKeys:
@"userId",@"id",
@"firstName",@"first_name",
@"lastName",@"last_name"
nil];
}@end
```