我正在制作任务管理器应用程序,我有两个实体 - 任务和任务类别,每个任务都有一个类别,而一个类别可以有多个任务。
类看起来像这样:
TaskCategory.h:
@class Task;
@interface TaskCategory : NSManagedObject
@property (nonatomic, retain) id color;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSSet *task;
@end
@interface TaskCategory (CoreDataGeneratedAccessors)
- (void)addTaskObject:(Task *)value;
- (void)removeTaskObject:(Task *)value;
- (void)addTask:(NSSet *)values;
- (void)removeTask:(NSSet *)values;
@end
Task.h:
@class TaskCategory;
@interface Task : NSManagedObject
@property (nonatomic, retain) NSDate * dueDate;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * done;
@property (nonatomic, retain) TaskCategory *category;
@end
在表格视图中显示任务列表时,如何访问每项任务的类别以获得它的颜色?
答案 0 :(得分:3)
您可以尝试:
task.category.color
这应该有用。