Note that there are some explanatory texts on larger screens.

plurals
  1. POGet index of array object
    primarykey
    data
    text
    <p>This is the code I'm trying to finish</p> <pre><code>-(IBAction)theButtonIsSelected:(id)sender { NSMutableDictionary *mutDict = [NSMutableDictionary dictionaryWithDictionary:[detailsDataSource objectAtIndex:detailIndex]]; [mutDict setObject:@"Yes" forKey:@"Favorite"]; NSString *nameString = [mutDict valueForKey:@"Name"]; NSArray *allObjects; allObjects = [[NSArray alloc] initWithContentsOfFile:path]; NSMutableArray *tmpMutArr = [NSMutableArray arrayWithArray:allObjects]; int index; //I think I just need a little piece right here to set the current allObjectsIndex to match nameString? [tmpMutArr replaceObjectAtIndex:index withObject:[NSDictionary dictionaryWithDictionary:mutDict]]; allObjects = nil; allObjects = [[NSArray alloc] initWithArray:tmpMutArr]; [allObjects writeToFile:path atomically:YES]; } </code></pre> <p>This is my question:</p> <pre><code>if (what I'm trying to do above can be done) { How to finish it? } else { How to make a function to change the "Favorite" key's value of plist object, when detailsDataSource not always containing the complete list of objects? That's why I'm trying to include allObjects and index in this code. } </code></pre> <p>EDIT:</p> <p>Code now look like this:</p> <pre><code> NSMutableDictionary *mutDict = [NSMutableDictionary dictionaryWithDictionary:[detailsDataSource objectAtIndex:detailIndex]]; [mutDict setObject:@"Yes" forKey:@"Favorite"]; NSString *nameString = [[detailsDataSource objectAtIndex:detailIndex] valueForKey:@"Name"]; NSArray *allObjectsArray = [[NSArray alloc] initWithContentsOfFile:path]; NSMutableArray *tmpMutArr = [NSMutableArray arrayWithArray:allObjectsArray]; if(int i=0;i&lt;[tmpMutArr count];i++) //Errors ^here and here^ { if([[tmpMutArr objectAtIndex:i] isKindOfClass:[NSDictionary class]]) { NSMutableDictionary *tempDict = [tmpMutArr objectAtIndex:i]; if([tempDict valueForKey:@"Name" == [NSString stringWithFormat:@"@%", nameString];) //Is this correct? { index = i; //index of dictionary } } } [tmpMutArr replaceObjectAtIndex:i withObject:[NSDictionary dictionaryWithDictionary:mutDict]]; allObjectsArray = nil; allObjectsArray = [[NSArray alloc] initWithArray:tmpMutArr]; [allObjectsArray writeToFile:path atomically:YES]; </code></pre> <p>Errors: 1 Expected expression 2 undeclared identifier 'i' how to declare I and fix the other error?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload