Monday, 15 June 2015

ios - How do I define a different database path for iPad/iPhone simulator? -



ios - How do I define a different database path for iPad/iPhone simulator? -

this way define path local sql database. noticed simulator in both iphone , ipad mode share same database.

- (nsstring *)recordarchivepath { nsarray *documentdirectories = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentdirectory = [documentdirectories objectatindex:0]; homecoming [documentdirectory stringbyappendingpathcomponent:@"store.data"]; } nspersistentstorecoordinator *psc = [[nspersistentstorecoordinator alloc] initwithmanagedobjectmodel:model]; nsstring *path = [self recordarchivepath]; nsurl *storeurl = [nsurl fileurlwithpath:path]; nserror *error = nil; nsdictionary *options = @{ nsmigratepersistentstoresautomaticallyoption : @yes, nsinfermappingmodelautomaticallyoption : @yes }; sqlitestore = [psc addpersistentstorewithtype:nssqlitestoretype configuration:nil url:storeurl options:options error:&error];

what have have different database each mode?

i have tried approach, failed:

#if target_os_iphone homecoming [documentdirectory stringbyappendingpathcomponent:@"store.data"]; #else homecoming [documentdirectory stringbyappendingpathcomponent:@"store-ipad.data"]; #endif

try following:

#define is_ipad ui_user_interface_idiom() == uiuserinterfaceidiompad

then can use

if (is_ipad) { homecoming [documentdirectory stringbyappendingpathcomponent:@"store-ipad.data"]; } else { homecoming [documentdirectory stringbyappendingpathcomponent:@"store.data"]; }

ios

No comments:

Post a Comment