Coder Social home page Coder Social logo

simpledata's Introduction

SimpleData

A friendly abstraction for CoreData

Aim: Gain all the speed of CoreData but with a friendly, ActiveRecord style interface.

Step 1: Install SimpleData

  • Add the SimpleData repository to your project
  • Add all the .m files in Lib to your target
    • Right click the .m file
    • In the target tab, check the box for your target

Step 2: Create a data model

  • Go to File > New File then choosing Resource > Data Model
  • Open the data model and edit it to your hearts desire
  • Tip: you might want to create date attributes called createdAt and updatedAt as they will come on handy later

Step 3: Create the class representations

  • In the data model editor, select classes you wish to use in your project
  • Choose File > New File. In the New File dialog, select Managed Object Class.
  • Depending on the version of Xcode you’re using, the Managed Object Class may be available in the iPhone OS section under Cocoa Touch Classes, or you may need to choose the template in the Mac OS X section, under Cocoa—either will work correctly.
  • Click Next. The correct location and targets should have been selected for you. Click Next to accept them.
  • You should see the Entity selection pane, with the Event entity selected. The “Generate accessors” and “Generate Objective-C 2.0 properties” options should also be selected.
  • Click Finish to generate the files.
  • In the header files for the generated classes, replace “: NSManagedObject” with “: SimpleModel”

You are now ready to start working with SimpleData

Step 4: Create a SimpleStore

  • First, import the SimpleStore header
    #import <SimpleStore.h>
  • To create or open an existing database simply call:
    [SimpleStore storeWithPath: @"path"];

Step 5: Enjoy!

  • To create an object:
    [User createWithAttributes:attributesDict];
    [User createWithName:@"Brian" email:@"[email protected]"];
    [User createWithEmail:@"[email protected]" name:@"John"];
  • To find an object:
    [User findByName:@"Brian"];
    [User findAll]
    NSArray *users = [User findAllByStarSign:@"Libra" sortBy:@"name" sortByDescending:@"createdAt"];
  • To update an object:
    User *u = [User findByName:@"Brian"];
    u.name = @"Brian Collins";
    [u save];
  • Setting non object attributes (unfortunately):
    [User createWithName:@"Brian" 
     smoker:[NSNumber numberWithBool:NO]];
  • Find or create an object if it doesn’t exist:
    [User findOrCreateByName:@"Brian" email:@"[email protected]"].email; // => @"[email protected]"
    [User findOrCreateByName:@"Brian" email:@"[email protected]"].email; // => @"[email protected]" because it exists

Running the test suite

  • Build and run with the target “Test” and watch the log output

Displaying SimpleData objects in a tableView

  • Subclass SDTableViewController

Limitations

  • Currently,
    • You may only have one SimpleStore open per thread.
    • There is no validation, but the standard coredata validation should still work.
    • You will get warnings unless you prototype the methods you use. See this wiki article

See Also

simpledata's People

Contributors

drewsmits avatar thinktopdown avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

nickbabenko

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.