我使用核心數據並有一個對象ExerciseForRoutine
。我目前手動創建它,然後設置屬性,這似乎浪費了代碼。有沒有什麼辦法可以創建自定義init()方法在一行來處理這個(我知道該怎麼做左右分配/ 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;
ExerciseForRoutine類
@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;
你不應該重寫初始化。有關信息[對象生命週期初始化和釋放]的文檔(https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdManagedObjects.html#//apple_ref/doc/) uid/TP40003397-SW2) –