Tuesday, 21 August 2012

NSMutableDict won't retain objects?


i need second set of eyes here. have done many times before out problem. getting 4 text files internet , using nsscanner read in each line, each txt file. @ point add each line of text nsstring , further add string nsmutablearray. when finished reading in txt file adds nsmutablearray nsmutabledictionary.

used nslog verify data exists in mutablearray when try verify saved mutabledictionary prints out keys , objects blank.

here log , can see clientarray hold values
here method far. @ bottom test it
code:
@interface viewcontroller : uiviewcontroller{      nsmutabledictionary *clienttableviewdict;      nsmutablearray *clientarray;        }

code:
-(void)backgroundnameload{ //load tableview lists      bool checkforfile;      int locationofscanner = 0;            nsmutablestring *tempstoragestring = [[nsmutablestring alloc] init];      clientarray = [[nsmutablearray alloc] init];      [color="red"]clienttableviewdict = [[nsmutabledictionary alloc] init];[/color]            nsfilemanager *filemanager = [nsfilemanager defaultmanager]; //create file manager object               (int = 0; < 4; i++) {          nsstring *verifylocalfile = [self datapathtoallfiles:i];          checkforfile = [filemanager fileexistsatpath:verifylocalfile]; // bool see if file exists            nslog(@"local file path %@", verifylocalfile);                if (checkforfile) {              nslog(@"the file here");          }                    else{              nslog(@"no file exists");              nsurl *filelocation = [self getnexturl:i];                        nsstring *currentclientlist = [nsstring stringwithcontentsofurl:filelocation encoding:nsutf8stringencoding error:nil];              nsscanner *scanner = [nsscanner scannerwithstring:currentclientlist];                            while (![scanner isatend]) {                  [scanner setscanlocation:locationofscanner];                  [scanner scanuptostring:@"\n" intostring:&tempstoragestring];                  locationofscanner = [scanner scanlocation];                  [clientarray addobject:tempstoragestring];              }              [color="red"][clienttableviewdict setvalue: clientarray forkey:[self dictname:i]];[/color]              nslog(@"clientarray: %@", clientarray);              locationofscanner = 0;              [clientarray removeallobjects];          }      }      nslog(@"client dicts: %@", clienttableviewdict);      nslog(@"items: %@", [clienttableviewdict objectforkey:@"wine"]);  }  
i have looked @ couple hours , can't track down problem.

 

it retain it. not create new copy of it. there none object multiple pointers pointing it. when (i have removed 2 lines inbetween have no effect on this)

code:
  [clienttableviewdict setvalue: clientarray forkey:[self dictname:i]];  [clientarray removeallobjects];  
you telling dict have pointer object pointed clientarray. same object. there 1 array. empty array. noted there 1 array. empties array dict has pointer to.
 


Forums iPhone, iPad, and iPod Touch iOS Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

No comments:

Post a Comment