Created
June 19, 2013 19:24
-
-
Save paulocoutinhox/5817206 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### NEW PRODUCT ###### | |
ARLazyFetcher *fetcher = [MyProduct lazyFetcher]; | |
[fetcher where:@"object = %@ AND object_id = %@", pObject, pObjectId, nil]; | |
NSArray *products = [fetcher fetchRecords]; | |
if ([products count] == 0) | |
{ | |
MyProduct *product = [MyProduct newRecord]; | |
product.title = pTitle; | |
product.image = pImage; | |
product.object = pObject; | |
product.object_id = pObjectId; | |
[product save]; | |
} | |
##### FINDALL PRODUCTS ###### | |
NSArray *products = [MyProduct allRecords]; | |
self.tableData = nil; | |
self.tableData = [[NSMutableArray alloc] init]; | |
for (MyProduct *product in products) | |
{ | |
NSDictionary *newObject = [[NSDictionary alloc] initWithObjectsAndKeys: | |
product.title , @"title", | |
product.image , @"image", | |
product.object , @"object", | |
product.object_id , @"object_id", | |
nil]; | |
[self.tableData addObject: newObject]; | |
} | |
[self.tableView reloadData]; | |
##### MY PRODUCT - HEADER ###### | |
#import <ActiveRecord/ActiveRecord.h> | |
@interface MyProduct : ActiveRecord | |
@property (nonatomic, retain) NSString *title; | |
@property (nonatomic, retain) NSString *image; | |
@property (nonatomic, retain) NSString *object; | |
@property (nonatomic, retain) NSString *object_id; | |
+ (NSString *)recordName; | |
@end | |
##### MY PRODUCT - IMPLEMENTATION ###### | |
#import "MyProduct.h" | |
@implementation MyProduct | |
@dynamic title; | |
@dynamic image; | |
@dynamic object; | |
@dynamic object_id; | |
+ (NSString *)recordName | |
{ | |
return @"my_product"; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment