CocoaPods trunk is moving to be read-only. Read more on the blog, there are 14 months to go.
| TestsTested | ✗ |
| LangLanguage | Obj-CObjective C |
| License | MIT |
| ReleasedLast Release | Nov 2015 |
Maintained by Zak Niazi.
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.
SnapIt encapsulates the common patterns of persisting data to permanent storage via a SQLite Connection.
#import "SnapIt.h"
@interface Cat : SnapItTo persist data, inherit from the SnapIt class.
SAVE methodCat *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 methodNSArray *cats = [Cat all];To retrieve all objects from the database, run the all method on the class you wish to query.
WHERE methodNSArray *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")
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")
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>"
]Zak Niazi, [email protected]
Daniel Wu, [email protected]
SnapIt is available under the MIT license. See the LICENSE file for more info.