【发布时间】:2013-02-28 21:30:15
【问题描述】:
我正在使用 MagicalRecord 来处理 Core Data 对象。我在使用 MR 将它们放入的 NSArray 检索核心数据对象时遇到问题……我似乎无法将数据从数组中取出并放入 NSManagedObject 中,因此我可以使用它。这是我的代码:
// create the predicate
NSArray *apptDataArray = [NSMutableArray new];
NSPredicate *predicate = ([NSPredicate predicateWithFormat:@"((aStartTime > %@) AND (aStartTime <= %@))", startDate, endDate]);
// find all appointments with that selected date
apptDataArray = [AppointmentInfo MR_findAllWithPredicate:predicate];
// now find the appointments for the selected date and put them in the schedule
if(apptDataArray.count > 0) {
for (NSManagedObject *AppointmentInfo in apptDataArray) {
NSLog(@"\n\n-->apptDataArray: %@", apptDataArray);
}
}
这是另一个类中的 AppointmentInfo 的定义:
@interface AppointmentInfo : NSManagedObject
@property (nonatomic, retain) NSDate * aStartTime;
@property (nonatomic, retain) NSDate * aEndTime;
@property (nonatomic, retain) NSString * aServiceTech;
@property (nonatomic, retain) NSString * aApptKey;
@property (nonatomic, retain) NSDate *aShortDate;
不知何故,我需要获取返回数组中的数据并将其放在 AppointmentInfo 中。我已经尝试了各种排列,查看了谷歌和 SO,但我找不到任何东西。我难住了!我该怎么做?
【问题讨论】:
-
失败的具体症状是什么?
-
这不是失败...我只是不知道如何将 MR 返回的 NSArray 数据获取到 AppointmentInfo 中,以便获取单独的字段(即 aStartTime、aEndTime)并使用它们。
标签: objective-c core-data magicalrecord