In my application I am having entity class like:
#import <Foundation/Foundation.h>
@interface classAbc : NSObject
{
NSString *strTitle;
int iId;
}
@property(nonatomic, retain) NSString *strTitle;
@property(nonatomic) int iId;
@end
and in my NSMutableArray I am storing objects of this class like:
classAbc *objAbc=[[classAbc alloc] init];
objAbc.iId=1;
objAbc.strTitle=@"Title 1";
classAbc *objAbc1=[[classAbc alloc] init];
objAbc1.iId=2;
objAbc1.strTitle=@"Title 2";
NSMutableArray *arrTemp=[[NSMutableArray alloc] initWithObjects:objAbc,objAbc1,nil];
[objAbc release];
[objAbc1 release];
and now runtime I want to retrieve Object from this array based on objAbc.iId condition like:
if arrTemp contains object having its iId value as 2 for example.
Can any one suggest way other than for loop iteration? As number objects can increase for loop will take lot of time to find it.
Thanks in advance.
After searching I got answer to this question. Using NSPredicate is the best way for such condition. Using NSPredicate we can apply condition on any member of the class object.
This is link for MAC OS X however this works on iPhone sdk with some changes.
NSPredicate