Skip to content

Instantly share code, notes, and snippets.

View TempViewController.m
@property (nonatomic, strong) NSArray *dataRows;
- (void)getTempData
{
NSArray *results = [[[SmartStoreInterface alloc] init] getAccount];
if(results){
_dataRows = results;
[self.tableView reloadData];
}
}
View RootViewController.m
- (void)tableView:(UITableView *)itemTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[itemTableView deselectRowAtIndexPath:indexPath animated:NO];
NSDictionary *obj = [_dataRows objectAtIndex:indexPath.row];
DetailViewController *detailController =
[[DetailViewController alloc] initWithName:[obj objectForKey:@"Name"]
id:[obj objectForKey:@"Id"]];
[self.navigationController pushViewController:detailController animated:YES];
View RootViewController.m
@property (nonatomic, strong) NSArray *dataRows;
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
SFRestRequest *request = [[SFRestAPI sharedInstance] requestForQuery:@"SELECT Id, Name FROM Account LIMIT 10"];
[[SFRestAPI sharedInstance] send:request delegate:self];
}
#pragma mark - SFRestAPIDelegate
View RootViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"SmartStore Sample App";
//スープ領域を作成
[[[SmartStoreInterface alloc] init] createAccountSoup];
}
View DetailViewController.m
- (void)pressSaveButton
{
NSDictionary *fields = @{@"Name": _nameField.text};
SFRestRequest *request = [[SFRestAPI sharedInstance] requestForUpdateWithObjectType:@"Account"
objectId:_idData
fields:fields];
[[SFRestAPI sharedInstance] send:request delegate:self];
}
#pragma mark - SFRestAPIDelegate
View SmartStoreInterface.m
NSString* const kAllAccountQuery = @"SELECT {Account:Id},{Account:Name} FROM {Account}";
- (NSArray*)getAccount
{
SFQuerySpec * querySpec = [SFQuerySpec newSmartQuerySpec:kAllAccountQuery withPageSize:10];
return [_store queryWithQuerySpec:querySpec pageIndex:0];
}
View SmartStoreInterface.m
- (void)upsertAccount:(NSDictionary*)account
{
if (nil != account) {
[_store upsertEntries:[NSArray arrayWithObject:account]
toSoup:kAccountSoupName];
}
}
View SmartStoreInterface.m
NSString* const kAccountSoupName = @"Account";
NSString* const kAllAccountQuery = @"SELECT {Account:Id},{Account:Name} FROM {Account}";
@interface SmartStoreInterface ()
@property (nonatomic, strong) SFSmartStore *store;
@end
@implementation SmartStoreInterface : NSObject