开发者

how to verify if an element exsit or not in an NSMutubleArray

I'm new to objective-c. I have an NSMutableArray . I wrote this:

for (int i=0; i<[allCombinations count]; i++)
{
    NSString *date = [[allCombinations objectAtIndex:i] objectForKey:@"keydate"];
    NSString *cachdepeDate = [date substringToIndex:8];
}

How can i see if cachdepeDate is alrady exsit in my NSMutbleArray?

If it is not exist how do I add it?

Should I make for loop, or there is a method for this?

Can i sort the NSMutbleArray?开发者_如何学JAVA

Dates are in this format: "20110531" "YYYYMMDD". Thank you!


Use the following

[yourArray containsObject:cachdepeDate];


NSArray already has the containsObject: method. But even if it didn't, this would be simple to write:

for (id object in array) {
    if ([object isEqual:cachdepeDate]) {
        // it's in there
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜