從數據庫文件中取數據我有兩個NSManagedObject類的UserInfo和部門(一對一和一對多的關係分別),這裏是我的代碼,問題使用NSPredicate
// UserInfo.h
@interface UserInfo : NSManagedObject
@property (nonatomic, retain) NSDate * bDate;
@property (nonatomic, retain) NSString * firstName;
@property (nonatomic, retain) NSString * lastName;
@property (nonatomic, retain) NSString * userName;
@property (nonatomic, retain) Department *dept;
@end
//Department.h
@class UserInfo;
@interface Department : NSManagedObject
@property (nonatomic, retain) NSString * id;
@property (nonatomic, retain) NSString * post;
@property (nonatomic, retain) NSString * location;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSSet *user;
@end
@interface Department (CoreDataGeneratedAccessors)
- (void)addUserObject:(UserInfo *)value;
- (void)removeUserObject:(UserInfo *)value;
- (void)addUser:(NSSet *)values;
- (void)removeUser:(NSSet *)values;
@end
從DB I使用,其效果很好
搜索特定用戶NSPredicate *predicate = [NSPredicate predicateWithFormat:@"firstName contains[cd] %@", NameTosearch];
但是,現在我可以用什麼樣的謂詞來獲取信息連接到特定部門的所有用戶?