@interface demodata : NSObject
{
NSString *Day;
NSString *content;
@property (nonatomic, retain) NSString *Day;
@property (nonatomic, retain) NSString *content;
}
-------
Test.m file--
NSMutableArray *sessions = [[NSMutableArray alloc] init];
demodata * sess = [[demodata alloc] init];
sess.Day=@"Monday";
sess.content=@"HI";
[sessions addObject :sess];
[sess release];
demodata * sess1 = [[demodata alloc] init];
sess1.Day=@"Tuesday";
sess1.content=@"Bye";
[sessions addObject :sess1];
[sess1 release];
我试过
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Day == %@", @"Monday"];
NSArray *filteredArray = [sessions filteredArrayUsingPredicate:predicate];
我的数组对象是类(nsobject)..
它不起作用......
如何按天过滤数组(会话)..
答案 0 :(得分:1)
您可以使用NSArray
s -filteredArrayUsingPredicate:
并传递NSPredicate
来描述您的需求。
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Day = %@", @"Tuesday"];
NSArray *filteredArray = [myArray filteredArrayUsingPredicate:predicate];
答案 1 :(得分:0)
此代码工作正常..问题是数组对象中有一些空格。