-2

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.

6
  • 2
    Explain your Problem.
    – Bhavin
    Commented Jul 29, 2013 at 9:20
  • where can i put an alert a message that Entered Playlists Already exists
    – ChenSmile
    Commented Jul 29, 2013 at 9:25
  • see this answer
    – Lithu T.V
    Commented Jul 29, 2013 at 9:30
  • There is a very useful method for this in NSarray i.e containObject.
    – 9to5ios
    Commented Jul 29, 2013 at 9:30
  • check now hope you got it now completely
    – 9to5ios
    Commented Jul 29, 2013 at 10:51

4 Answers 4

1

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
0
0
if (![array containsObject:someObject]) {
// ...
}
0

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..

0

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

Parameters

anObject

An object.

Return Value

YES if anObject is present in the array, otherwise NO.

Discussion

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.

2
  • k dude. containObject works with NSMutable array also..can u tell me
    – ChenSmile
    Commented Jul 29, 2013 at 9:54
  • check full explanation now ! NSMutableArray is subclass or NSArray :)
    – 9to5ios
    Commented Jul 29, 2013 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.