@cobbal Vraiment super réponse :) Après avoir vu votre réponse, j'ai vraiment compris la différence. Mais au début, cela m'a semblé un peu déroutant puisque je suis novice en programmation Objective-C, donc je veux juste améliorer votre réponse en donnant un exemple. Il aide à d'autres l'espoir débutants quand ils regardent l'exemple :)
#import<Foundation/Foundation.h>
int main()
{ int i;
printf("Enter 1 to perform removeObject function.\n Enter 2 to perform removeObjectIdenticalTo functionality.\n ");
scanf("%d",&i);
@autoreleasepool{
NSString* color;// int count;
NSString * s1 = [NSMutableString stringWithString: @"Red"];
NSString * s2 = [NSMutableString stringWithString: @"Yellow"];
NSString * s3 = [NSMutableString stringWithString: @"Red"];
NSString * s4 = [NSMutableString stringWithString: @"Cyan"];
NSMutableArray * myColors = [NSMutableArray arrayWithObjects: s1,s2,s3,s4,nil];
if(i == 1)
{
[myColors removeObject: s1]; //will remove both s1 and s3 object because their contents are same
//we can also use [myColors removeObject: @"Red"]; instead of above statement. However the functionality remains same .
for(color in myColors)NSLog(@"%@",color);
}
else if (i == 2){
[myColors removeObjectIdenticalTo: s1]; //deletes only s1 object in the array myColor
for(color in myColors)NSLog(@"%@",color);
}
}
return 0;
}
PS: Ceci est juste un exemple. Vous pouvez trouver la réponse dans la réponse de @cobbal.
Juste pour noter que, puisque cette question a été posée, la documentation pour les deux méthodes a été mise à jour pour indiquer explicitement comment les objets sont sélectionnés pour la suppression. – JeremyP