In my app,User can add templates. On this template he adds any number of images & text views. He has option to change textviews properties like font name, font color,font size & many more. Image operations like rotate image to any angle,increase / decrease size at runtime and many more. After doing this, user saves this template & see later he wants. So I want to store this all operation perform by user & view on recent list. So How to do this?
Asked
Active
Viewed 370 times
2 Answers
1
sqlite3 *database;
dbName=@"dataTable.sqlite";
NSArray *documentpath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentdir=[documentpath objectAtIndex:0];
dbPath=[documentdir stringByAppendingPathComponent:dbName];
sqlite3_stmt *compiledStmt;
if(sqlite3_open([dbPath UTF8String], &database)==SQLITE_OK){
NSLog(@"Name:%@,Company:%@,URL:%@",model.personName,model.companyName,model.imgurl);
const char *insertSQL="insert into Persons(PersonName,CompanyName,ImgUrl,PersonImage)values(?,?,?,?)";
if(sqlite3_prepare_v2(database,insertSQL, -1, &compiledStmt, NULL)==SQLITE_OK){
sqlite3_bind_text(compiledStmt,1,[model.personName UTF8String],-1,SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStmt,2,[model.companyName UTF8String],-1,SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStmt,3,[model.imgurl UTF8String],-1,SQLITE_TRANSIENT);
NSData *imageData=UIImagePNGRepresentation(imageView.image);
sqlite3_bind_blob(compiledStmt, 4, [imageData bytes], [imageData length], NULL);
NSLog(@"Prepare");
sqlite3_step(compiledStmt);
}
sqlite3_finalize(compiledStmt);

Mitul Nakum
- 5,514
- 5
- 35
- 41
0
I suggest to save in your db the key to retrieve image from disk.
After that, use NSArchiver
and NSUnarchiver
to get images from disk.
UIImage *img = [NSKeyedUnarchiver unarchiveObjectWithFile:db.ImgKey];
Saving images in db is heavy and discorages and heavy.
hope this helps.

elp
- 8,021
- 7
- 61
- 120