Am a newbie to App development (to Apple related development itself, I should say!) I am writing a simple app, in which am doing some simple SQLite3 operations to store and retrieve data.
In the ViewController class:
On button press in the UI, am persisting some data into the database. And also, consequently retrieving and displaying some data.
In another class called DatabaseOperations (I have put in all database related operations into this):
I have methods which do storage/retrieval of data.
The above code works fine for me. The only problem is with 'calling' the methods in DatabaseOperations from the ViewController.
In order to do this, am instantiating DatabaseOperations class in 'viewDidLoad' of ViewController. There is a problem with this approach, because, as you might have guessed, the data persisted in the DB gets wiped off every time I quit the app. Initially I was having DB operations too in the ViewController class itself. At that time, this wiping-off didn't happen.
I tried making the methods in the DatabaseOperations class as 'class methods' (putting a '+', instead of '-'), but that is causing other errors as am using some instance variables in those methods, which is not compliant.
How can I make sure that the data in SQLite3 is not wiped off after I quit the app? Please help!
This is the code snippet:
VIEW CONTROLLER CLASS
// import and synthesize statements
DatabaseOperations *dbOps;
…
…
- (void)viewDidLoad
{
dbOps = [[DatabaseOperations alloc] init];
[dbOps openDB];
…
}
DATABASEOPERATIONS iNTERFACE:
#import <Foundation/Foundation.h>
#import "sqlite3.h"
@interface DatabaseOperations : NSObject
@property (nonatomic) sqlite3 *database;
// Method to open the database
-(void) openDB;
…