ios - Sqlite tutorial overview for my cocoa mac application in objective c -


i having cocoa application mac in objective c.

now, in app want implement sqlite database did ios apps.

as new mac development, not sure how implement in cocoa application. how make sqlite connection app?

i used sqlite.h , sqlite.m files , used below code.

-(void)databaseopen {     nsarray *path = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);     nsstring *documentsdirectory = [path objectatindex:0];     nsstring *mydbnew = [documentsdirectory stringbyappendingpathcomponent:@"schoolapp.sqlite"];     database = [[sqlite alloc] init];     [database open:mydbnew]; } - (void)createeditablecopyofdatabaseifneeded {     // first, test existence.     bool success;     nsfilemanager *filemanager = [nsfilemanager defaultmanager];     nserror *error;     nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);     nsstring *documentsdirectory = [paths objectatindex:0];       nsstring *writabledbpath = [documentsdirectory stringbyappendingpathcomponent:@"schoolapp.sqlite"];       /*if([[nsfilemanager defaultmanager] fileexistsatpath:writabledbpath]){      [[nsfilemanager defaultmanager] removeitematpath:writabledbpath error:nil];      }      */     success = [filemanager fileexistsatpath:writabledbpath];      if (success) return;     // writable database not exist, copy default appropriate location.     nsstring *defaultdbpath = [[[nsbundle mainbundle] resourcepath] stringbyappendingpathcomponent:@"schoolapp.sqlite"];      ////nslog(@"default : %@",defaultdbpath);     success = [filemanager copyitematpath:defaultdbpath topath:writabledbpath error:&error];      if (!success) {         nsassert1(0, @"failed create writable database file message '%@'.", [error localizeddescription]);      } } 

but how in cocoa application?

please can guide me.

thanks...

you should able re-use existing code both osx , ios rely on foundation.framework classes, not uikit or appkit.

note: shouldn't using nsassert signal errors in code these can removed @ compile time if ns_block_assertions defined; instead throw nsexception.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -