Skip to content

zniazi/SnapIt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SnapIt

[![CI Status](http://img.shields.io/travis/Zak Niazi/SnapIt.svg?style=flat)](https://travis-ci.org/Zak Niazi/SnapIt) Version License Platform

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

You must add "libsqlite3.dylib" to your "Linked Frameworks and Libraries" section of your application.

Persisting a SnapIt Resource.

SnapIt encapsulates the common patterns of persisting data to permanent storage via a SQLite Connection.

#import "SnapIt.h"
@interface Cat : SnapIt

To persist data, inherit from the SnapIt class.

SAVE method

Cat *mits = [[Cat alloc] init];
mits.name = @"Mits";
mits.color = @"orange";
[mits save];

To add an object to the database, modify it's attributes and run the save method.

ALL method

NSArray *cats = [Cat all];

To retrieve all objects from the database, run the all method on the class you wish to query.

WHERE method

NSArray *people = [Person where:@"name='Beth'"];
Person *beth = people[0];

To retrieve an object from the database meeting a specific criteria, enter a where clause on the class in question with the where clause formatted as "object_property=value"

DELETE method

[lucy deleteSelf];

To delete an object from the database, run deleteSelf on the instance.

FETCH method

[beth fetch];

To update an object with it's values in the database, run the fetch method on the instance. An example of when this is needed is after deleting an object with an association to the class. Run fetch to refresh it's data.

BELONGS TO association

@property (strong, nonatomic) Person *person;

To set up a belongs to association, simply list a property in the header file with the class name. The name of the property must be the same as the class name, non pluralized. (i.e Cat => "cat")

Example Usage

Person *beth = [[Person alloc] init];
beth.name = @"Beth";
[beth save];

Cat *bubbles = [[Cat alloc] init];
bubbles.name = @"Bubbles";
bubbles.color = @"grey";
bubbles.person = beth;
[bubbles save];

bubbles.person => <Person: 0x7ff323f33a20>

HAS MANY association

@property (strong, nonatomic) NSArray *cats;

To set up a has many association, list an array property in the header file. The name of the property must be the same as the pluralized class name. (i.e Cat => "cats")

Example Usage

Person *beth = [[Person alloc] init];
NSArray *allCats = [Cat all];
beth.cats = allCats;
[beth save];

beth.cats => [
"<Cat: 0x7ff589f5ccc0>",
"<Cat: 0x7ff589f5d360>",
"<Cat: 0x7ff589f5dc70>",
"<Cat: 0x7ff589f5ead0>",
"<Cat: 0x7ff589f618a0>",
"<Cat: 0x7ff589f5f0f0>"
]

Requirements

Installation

SnapIt is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SnapIt"

Authors

Zak Niazi, zniazi1029@gmail.com

Daniel Wu, dan.wu.87@gmail.com

License

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

About

A Core Data Alternative using Active Record like syntax to persist and fetch data.

Resources

License

Stars

Watchers

Forks

Packages

No packages published