samedi 27 juin 2015

Add and save item to favorites

I have a tableview with many words and I want to add the favorites feature so each detail view can have a button to save as a Favorite. This is my code, but doesn't work, after pressing the button I get this error (property lists cannot contain objects of type 'CFType'), but if I use slovoItem.slovo or slovoItem.definice, value is saved correctly. slovoItem has values slovoItem.slovo and slovoItem.definice and I need to save completely slovoItem.

Code in my DetailViewController:

- (IBAction) addToFavorites:(id)sender
{
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];


    NSMutableArray *tempArray = [[prefs objectForKey:@"favorite"] mutableCopy];
    favorite = tempArray;

    [favorite addObject:self.slovoItem];

    [prefs setObject:favorite forKey:@"favorite"];

    for (id obj in favorite)
    {
        NSLog(@"%@", obj);
    }
}

Aucun commentaire:

Enregistrer un commentaire