J'ai créé le modèle que vous pouvez y voir: http://i.imagehost.org/0836/2009-11-08_14_37_41.pngCore Data: re-création à-plusieurs
Je veux stocker des informations sur les catégories sonores et certains sons échantillon pour chaque catégorie. La catégorie a Nom (NSString) et SoundsRelation (NSSet de NSData, qui représente les sons).
Voici le problème: Par exemple, j'ai une catégorie qui contient plusieurs sons associés. On suppose nombre de sons est 3. Donc, si je
NSLog(@"description: \n%@", category);
Je verrai informations sur le nom et ces trois sons. Quelque chose comme ceci:
Name = "Cat1";
SoundsRelation = (
0x174e90 <x-coredata://2E783972-3772-4CCA-9676-1D5F732D1FD2/Sounds/p9>,
0x174ea0 <x-coredata://2E783972-3772-4CCA-9676-1D5F732D1FD2/Sounds/p10>,
0x174eb0 <x-coredata://2E783972-3772-4CCA-9676-1D5F732D1FD2/Sounds/p11>
);
Ensuite, je veux effacer cette catégorie de sons. Je veux mettre SoundsRelation à zéro.
je fais:
[category setValue:nil forKeyPath:@"SoundsRelation"];
Maintenant, si je
NSLog(@"description: \n%@", category);
j'aurai quelque chose comme:
Name = "Cat1";
SoundsRelation = (
);
Eh bien, il semble que Cat1 ne pas les sons associés avec ça.
Maintenant, je sauvegarde mon managedObjectContext en utilisant la méthode [managedObjectContext save:]
et QUIT APP.
Quand je relaund mon application et faire
NSLog(@"description: \n%@", category);
j'aurai:
Name = "Cat1";
SoundsRelation = (
0x174e90 <x-coredata://2E783972-3772-4CCA-9676-1D5F732D1FD2/Sounds/p9>,
0x174ea0 <x-coredata://2E783972-3772-4CCA-9676-1D5F732D1FD2/Sounds/p10>,
0x174eb0 <x-coredata://2E783972-3772-4CCA-9676-1D5F732D1FD2/Sounds/p11>
);
Je vois mes précédents sons!
Maintenant, si je substitue SoundsRelation avec un autre NSSet qui contient 5 AUTRES sons: [category setValue: otherSetWithFiveSounds forKeyPath: @ "SoundsRelation"];
Et faites: NSLog (@ "description: \ n% @", catégorie); Je vois: Nom = "Cat1"; SoundsRelation = ( 0x174e90, 0x174ef0, 0x174ab0, 0x1743b0, 0x1744b0);
Maintenant, si je sauve, quitter et relancer, après NSLogging ma catégorie je vois:
Name = "Cat1";
SoundsRelation = (
0x174e90 <x-coredata://2E783972-3772-4CCA-9676-1D5F732D1FD2/Sounds/p9>,
0x174ea0 <x-coredata://2E783972-3772-4CCA-9676-1D5F732D1FD2/Sounds/p10>,
0x174eb0 <x-coredata://2E783972-3772-4CCA-9676-1D5F732D1FD2/Sounds/p11>,
0x174e90 <x-coredata://2E783972-3772-4CCA-9676-1D5F732D1FD2/Sounds/p12>,
0x174ef0 <x-coredata://2E783972-3772-4CCA-9676-1D5F732D1FD2/Sounds/p13>,
0x174ab0 <x-coredata://2E783972-3772-4CCA-9676-1D5F732D1FD2/Sounds/p14>,
0x1743b0 <x-coredata://2E783972-3772-4CCA-9676-1D5F732D1FD2/Sounds/p15>,
0x1744b0 <x-coredata://2E783972-3772-4CCA-9676-1D5F732D1FD2/Sounds/p16>
);
Je vois SONS VIEUX + NOUVEAU SONS! Pourquoi? Que dois-je faire pour remplacer complètement les relations OLD à NEW relations?
Je dois noter que tous les objets gérés (de toutes les entités) sont dans le même contexte. – beefon