In my playlist view, I have created several playlists and if I am creating a new playlist, which already exists in my array, how can I make condition in my alert view in 'SAVE' button that name already exists .
Thanks in advance.
In my playlist view, I have created several playlists and if I am creating a new playlist, which already exists in my array, how can I make condition in my alert view in 'SAVE' button that name already exists .
Thanks in advance.
you can do it with containsObject
method of NSMutableArray
like bellow bellow code..
NSMutableArray *copyItems = [NSMutableArray array];
for (id yourName in yourMainArray)
if ([copyItems containsObject:yourName])
//display Alert message that name already exist
else
//Add object here
If you want to check out only one value in Array then you can use only bellow code..
if ([yourMainArray containsObject:yourName])
//display Alert message that name already exist
else
//Add object here
try to access the plist file using the nsfilemanager and get the dictionary into nsdictionary object and verify all the keys with you have in that dictionary.Access the plist file and verify it.It is the easy way..
There is a very useful method for this in NSarray i.e containObject. containsObject: Returns a Boolean value that indicates whether a given object is present in the array.
- (BOOL)containsObject:(id)anObject
anObject
An object.
YES if anObject is present in the array, otherwise NO.
This method determines whether anObject is present in the array by sending an isEqual: message to each of the array’s objects (and passing anObject as the parameter to each isEqual: message).
//appDelegate.list is NSArray you can define in your delegate in which we have to use check our item.
NSMutableArray *add=[[NSMutableArray alloc]init];
for (Item *item in addList){
if ([appDelegate.list containsObject:item])
{}
else
[add addObject:item];
}
Then I iterate over the add array and insert items.