SimpleRemoteObject 0.0.8

SimpleRemoteObject 0.0.8

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Unclaimed.


Downloads

Total18
Week0
Month0

Installs

Apps3
powered by Segment

GitHub

Stars7
Watchers3
Forks4
Issues0
Contributors2
Pull Requests1

Code

Files6
LOCLines of Code 239


  • By
  • Hal Seki

SimpleRemoteObject is a simple Objectie-C library that can create your classes' instance from server-side JSON text. I created this library inspired by NSRails framework. NSRails is awesome framework but it is suitable for Active-Record. Since I had to read data from NON-RAILS server, I made own library.

For example, you can get User class instance with below code.

[User fetchAsync:^(NSArray *allRemote, NSError *error) {
    if (error){
        //Do error handling
    }else{
        for (User* user in allRemote){
            NSLog(@"my name is:%@",user.name);
        }
    }
}];

Features

  • Create object instance from server side JSON text
  • Server side JSON text does not need to well-structured with local objects.

CAUTION

Currently this library is providing just simple usecase. Feel free to add your own usecases and contribute! ;)

Dependencies

  • iOS 5.1+
  • AFNetworking

Getting started

  1. Install

    SimpleRemoteObject is supporting cocoapods. Please add below line to your Podfile and run pod install.

    pod 'SimpleRemoteObject'
    
  2. Make an Objective-C class and have it subclass SRSimpleRemoteObject and set properties.

    For example, if the server return below JSON for http://your_server/users.json:

    {
     meta: {
       limit: 20,
       next: null,
       offset: 0,
       previous: null,
       total_count: 3
    },
    objects: [
     {
       id: 2,
       name: "Daniel",
       email: "[email protected]",
       age: 25
     },
     {
       id: 2,
       name: "Mario",
       email: "[email protected]",
       age: 30
     },
     {
       id: 3,
       name: "Hal",
       email: "[email protected]",
       age: 32
     }
    ]
    }
    

    You can make an object like this.

    #import <SimpleRemoteObject/SRSimpleRemoteObject.h>
    @interface User : SRSimpleRemoteObject
    @property(nonatomic,retain) NSString *name;
    @property(nonatomic,retain) NSString *email;
    @property(nonatomic) int age;
    @end
    
  3. Implement representUrl and resultKey methods

    #import "User.h"
    
    @implementation Tag
    +(NSString *)representUrl{
       return @"users.json";
    }
    +(NSString *)resultKey{
       return @"objects"; // key of target JSON object
    }
    @end
    
  4. Set base url of server API on somewhere.

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
       [SRRemoteConfig defaultConfig].baseurl = SERVER_URL;
    
       // Override point for customization after application launch.
       return YES;
    }
    
  5. Retrieve data

    [User fetchAsync:^(NSArray *allRemote, NSError *error) {
       if (error){
           //Do error handling
       }else{
           for (User* user in allRemote){
               NSLog(@"my name is:%@",user.name);
           }
       }
    }];
    

Documentation

Sorry, not provided yet.

Test Code may help your understanding.

TODOs

  • Imprement CRUD support
  • Support CoreData

Contribution

  • Bug report: please make a ticket here.
  • Pull request: of course, you are welcome!

License

SimpleRemoteObject is available under the MIT license. See the LICENSE file for more info.

Credits

Version 0.0.6

SimpleRemoteObject is written and maintained by Hal Seki. I've learned and inspired by NSRails project, many thanks there!