我必须对Checkin和FriendList进行类。将字符串与NSArray比较
Checkin.h
@interface Checkin : NSObject {
NSString *name;
NSString *profID;
NSString *place;
NSString *photoURL;
NSMutableArray *taggedID;
NSMutableArray *taggedName;
和Friendlist.h
@interface FriendList : NSObject {
NSString *name;
NSString *profID;
}
我所试图做的是给每个checkin.profid(大约5-6)与friendlist.h比较(200-5000)。 我试图用for循环做,但当检查第二个checkin.profid崩溃。 这是我的方法:
for(int i=0; i<[checkinArray count];i++){
Checkin *tempcheck = [[Checkin alloc] init];
tempcheck = [checkinArray objectAtIndex:i];
for(int j=0;j<[friendsArray count]; j++){
NSLog(@"count %d",j);
FriendList *tempfriend = [[FriendList alloc] init];
tempfriend = [friendsArray objectAtIndex:j];
if([tempcheck.profID isEqualToString:tempfriend.profID]){
NSLog(@"Find prof id same for : %@",tempcheck.name);
break;
}
else
NSLog(@"Not found id same for: %@",tempcheck.name);
[tempfriend release];
}
[tempcheck release];
}
}
有没有什么更好的办法来做到这一点比较呢?因为它也太慢了。 预先感谢您
这样的事吗? NSString * tempProfID = @“123456”NSPredicate * predicate = [NSPredicate predicateWithFormat:@“profID ==%@”,]; NSArray * results = [directoryContents filteredArrayUsingPredicate:predicate]; – BlackM 2011-05-30 20:19:49