Skip to content

Instantly share code, notes, and snippets.

@Kevinwlee
Created October 1, 2010 13:53
Show Gist options
  • Save Kevinwlee/606245 to your computer and use it in GitHub Desktop.
Save Kevinwlee/606245 to your computer and use it in GitHub Desktop.
#define YOUR_MODEL_SAVED @"YOUR_MODEL_SAVED_NOTIFICATION"
//
// Prefix header for all source files of the 'bizeeti-iphone' target in the 'bizeeti-iphone' project
//
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "Globals.h"
#endif
-(void)save:(YourModleObject *) model{
FMDatabase *db = [self db];
if(![db open]) {
NSLog(@"Error opening sqlite database!");
exit(1);
}
[db beginTransaction];
@try
{
if(model.itemId != 0){
[self updateYourModelObject:model withDB:db];
}
else {
[self createYourModelObject:model withDB:db];
}
[db commit];
[[NSNotificationCenter defaultCenter] postNotificationName:YOUR_MODEL_SAVED object:bizFocusItem];
}
@catch (id exception) {
NSLog(@"Rolling back, due to error!");
[db rollback];
@throw;
}
@finally {
[db close];
}
}
[[NSNotificationCenter defaultCenter] postNotificationName:YOUR_MODEL_SAVED object:bizFocusItem];
-(void)loadData{
YourModelService *svc = [[YourModelService alloc] init];
self.data = [svc ViewModels];
[self.tableView reloadData];
[svc release];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self loadData];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadData) name:YOUR_MODEL_SAVED object:nil];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment