iphone - correct way to sharing nsarray (3.1M size) between views -


i'm reading appdelegate not small array.

nsarray *mycountryspecific = [[nsarray alloc] initwithcontentsofurl:[[nsbundle mainbundle] urlforresource:@"nexttwoweekevents" withextension:@"ary"]]; self.mycountryspecificcodeslist = mycountryspecific; [mycountryspecific release],mycountryspecific = nil; 

to keep in memory, declared property

@property (nonatomic, retain) nsarray *mycountryspecificcodeslist; 

but main view have go 2 steps while using it, under event controller have event detailed view controller necessary part of array (based on predicate).

my current design read array not appdelegate, event detailed view controller when necessary.

can u share u experience? if better load array appdelegate , keep in memory, please advice correct way send access property between classes without memory leaks.

eventstableviewcontroller *events = [[eventstableviewcontroller alloc] initwithnibname:@"eventstableviewcontroller" bundle:nil]; self.eventlistcontroller = events;  promoview *promo = [[promoview alloc] initwithnibname:@"promoview" bundle:nil];  uinavigationcontroller *navigationcontroller = [[uinavigationcontroller alloc] init]; [navigationcontroller pushviewcontroller:events animated:no];  uitabbarcontroller *tabbar = [[uitabbarcontroller alloc] init]; self.tabbarcontroller = tabbar;  [tabbar setviewcontrollers:[nsarray arraywithobjects:navigationcontroller,promo,nil]];  eventlistcontroller.managedobjectcontext = self.managedobjectcontext;  [self.window addsubview:tabbarcontroller.view]; 

solution after playing controllers, find solution. still read array file everytime when showing detailed page, dictionary, key first world find , array cay result need. array transer 34k , code, make case intensive search in keys is:

nsdictionary *mycountryspecific = [[nsdictionary alloc] initwithcontentsofurl:[[nsbundle mainbundle] urlforresource:@"countryspecific" withextension:@"dict"]]; nsset * myset = [mycountryspecific keysofentriespassingtest:^(id key, id obj, bool *stop) {     if([key compare:countryname options:nscaseinsensitivesearch] == nsorderedsame) {         return yes;     }         else         return no;     }];  nsarray *result = [mycountryspecific valueforkey:[myset anyobject]]; 

this way working on iphone 3g :) , of course, better on emulator ;-)

rather using 1 massive array that's held entirely in memory, i'd suggest storing list of country-specific codes in core data database.

by doing so, use batched fetches , nsfetchedresultscontroller load whatever information needed present user @ given moment , nothing more. reduce application's overall memory usage, , lead faster startup , load times.

each view controller have own nsfetchedresultscontroller instance accessing database, providing different perspectives on data.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -