Skip to content

Instantly share code, notes, and snippets.

@halsk
Created March 16, 2013 15:35
Show Gist options
  • Save halsk/5176915 to your computer and use it in GitHub Desktop.
Save halsk/5176915 to your computer and use it in GitHub Desktop.
サーバの JSON テキストから Objective-C のインスタンスを生成するライブラリ、SimpleRemoteObject を公開しました。 ref: http://qiita.com/items/049b9c4584769fe37896
[User fetchAsync:^(NSArray *allRemote, NSError *error) {
if (error){
//Do error handling
}else{
for (User* user in allRemote){
NSLog(@"my name is:%@",user.name);
}
}
}];
#import <SimpleRemoteObject/SRSimpleRemoteObject.h>
@interface User : SRSimpleRemoteObject
@property(nonatomic,retain) NSString *name;
@property(nonatomic,retain) NSString *email;
@property(nonatomic) int age;
@end
#import "User.h"
@implementation Tag
+(NSString *)representUrl{
return @"users.json"; // server path
}
+(NSString *)resultKey{
return @"objects"; // key of target JSON object
}
@end
{
meta: {
limit: 20,
next: null,
offset: 0,
previous: null,
total_count: 3
},
objects: [
{
id: 2,
name: "Daniel",
email: "daniel@example.com",
age: 25
},
{
id: 2,
name: "Mario",
email: "mario@example.com",
age: 30
},
{
id: 3,
name: "Hal",
email: "hal@example.com",
age: 32
}
]
}
#import <SimpleRemoteObject/SRSimpleRemoteObject.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[SRRemoteConfig defaultConfig].baseurl = SERVER_URL;
// Override point for customization after application launch.
return YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment