iphone - Array of plist update data -
i have 2 arrays init 2 different plist files, plist files inside document folder not in bundle editable.
progress = [[nsmutablearray alloc] initwithcontentsoffile:[self progressfilepath]]; easy = [[nsmutablearray alloc] initwithcontentsoffile:[self easyfilepath]];
the progress plist empty insted easy is:
<array> <dict> <key>titleen</key> <string>hunter</string> <key>status</key> <integer>0</integer> <key>image</key> <string></string> </dict> </array>
now in view have tableview loaded easy , element press in row, if it’s status 0 goes progress plist, set object key image in dog.png in progress.plist set object 0 key status in easy one. did this:
nsnumber *status = [[easy objectatindex:indexpath.row] objectforkey:@"status"]; if ([status intvalue] == 0) { [progress addobject:[easy objectatindex:indexpath.row]]; int progresstot = [progress count]; (int i=0; i<progresstot; i++) { if ([[progress objectatindex:i] objectforkey:@"titleen"] == [[easy objectatindex:indexpath.row] objectforkey:@"titleen"]) { [[progress objectatindex:i] setobject:@"dog.png" forkey:@"image"]; } } [progress writetofile:[self progressfilepath] atomically:yes]; [[easy objectatindex:indexpath.row] setobject:[nsnumber numberwithint:1] forkey:@"status"]; [easy writetofile:[self easyfilepath] atomically:yes]; }
everything work fine, can’t understand why @ end of method have progress.plist element dog.png have dog.png on easy one. (status updated on easy , works dog.png on both). can me? can’t understand what’s wrong.
[progress addobject:[easy objectatindex:indexpath.row]];
you add object p1 == [easy objectatindex:indexpath.row] progress array, progress array retained p1 , has 1 of elements. didn't create new object, retained existing 1 - p1.
for (int i=0; i<progresstot; i++) { if ([[progress objectatindex:i] objectforkey:@"titleen"] == [[easy objectatindex:indexpath.row] objectforkey:@"titleen"]) { [[progress objectatindex:i] setobject:@"dog.png" forkey:@"image"]; } }
- in if-statement want compare objects' content, not pointers, guess.
- once again, in both arrays have pointer (p1) same object, when [p1 setobject:forkey:]; - both arrays.
Comments
Post a Comment