我使用 Core Data 并有一个 object ExerciseForRoutine
。我目前正在手动创建它,然后设置它的属性,这似乎浪费了代码。有什么方法可以创建一个自定义的 init 方法来在一行中处理这个问题(我知道如何处理 alloc/init,但核心数据有不同的 init 方法..)
当前代码:
ExerciseForRoutine *exerciseForRoutine = (ExerciseForRoutine *)[NSEntityDescription insertNewObjectForEntityForName:@"ExerciseForRoutine" inManagedObjectContext:managedObjectContext];
exerciseForRoutine.name = self.selectedExercise;
exerciseForRoutine.timeStamp = date;
exerciseForRoutine.muscleGroup = self.muscleName;
exerciseForRoutine.musclePicture = self.muscleURL;
例行练习课
@class Routine;
@interface ExerciseForRoutine : NSManagedObject {
@private
}
@property (nonatomic, strong) NSDate * timeStamp;
@property (nonatomic, strong) NSString * name;
@property (nonatomic, strong) NSString * muscleGroup;
@property (nonatomic, strong) NSString * musclePicture;
@property (nonatomic, strong) Routine * exerciseToRoutine;
@end
@implementation ExerciseForRoutine
@dynamic timeStamp;
@dynamic name;
@dynamic muscleGroup;
@dynamic musclePicture;
@dynamic exerciseToRoutine;