CocoaPods trunk is moving to be read-only. Read more on the blog, there are 12 months to go.
| TestsTested | ✓ |
| LangLanguage | Obj-CObjective C |
| License | MIT |
| ReleasedLast Release | Apr 2015 |
Maintained by Oscar Swanros.
PTModel is a simple object store for persisting data on iOS applications.
PTModel
Please note: this is in no way an attempt to replace CoreData. Its way far from that. If you're looking for an alternative for CoreData, you may want to take a look at FCModel.
PTModel serves well when you only need to persist a set of data, without worrying too much about performance.
PTModel is not designed to be a full-featured object graph. If what you need is save multiple entities, related to each other, what you want is to use CoreData.
To use PTModel, you just need to subclass it:
// Record.h
#import <PTModel/PTModel.h>
@interface Record : PTModel
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *band;
@end
// Record.m
#import "Record.h"
@implementation Record
@endRecord *newRecord = [Record new]; // Create a new object
newRecord.title = @"Divine Discontent";
newRecord.band = @"Sixpence None The Richer";
[newRecord save]; // Save your object to the storeIn this version of PTModel you can retrieve objects by querying for them:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"title = %@", @"Divine Discontent"];
Record *retrievedRecord = [[Record instancesFilteredWithPredicate:predicate] firstObject];Each instance of your subclass also has a guid property that is set right before the object is first saved. This is a unique ID, and you can use it to retrieve a specific object, too:
Record *favouriteRecord = [Record new];
favouriteRecord.title = @"Strangeland";
favouriteRecord.band = @"Keane";
[favouriteRecord save]; // Here, the guid property is set on favouriteRecord
NSString *recordId = favouriteRecord.guid;
Record *recordToShare = [Record instanceWithId:recordId];If you have an instance of your subclass of PTModel, you can simply modify one of its properties and call save on it to persist the changes.
// Using favouriteRecord from above...
favouriteRecord.title = @"Night Train";
[favouriteRecord save];You can call remove on your PTModel subclass instance to delete it from the store.
[favouriteRecord remove];If you want to empty your whole store, you can call removeAllInstances on your subclass:
[Record removeAllInstances];PTModel is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod "PTModel"Oscar Swanros @ Pacific3, [email protected]
PTModel is available under the MIT license. See the LICENSE file for more info.