我有2个NSMutableArrays,它们将用于填充表格单元格,我不确定Core数据是否可以处理NSMutableArrays但是有没有办法保存这些已存在数据的数组?以后还可以添加到这些数组吗?我的目标是允许用户同时添加新代码和描述,从而导致添加新的表格单元格。以下是我创建两个数组的方式,有人可以告诉我如何将这些数据放入Core数据中吗?
@property(strong,nonatomic)NSMutableArray *presetList;
@property(strong,nonatomic)NSMutableArray *codeDescArray;
- (instancetype)init {
self = [super init];
if (self) {
self.presetList = [NSMutableArray arrayWithObjects:@"AS",
@"BCNU",
@"CL",
@"CT",
@"CUL",
@"K",
@"QSL",
@"QSL?",
@"QRX?",
@"QRV",
@"QRV?",
@"QTH",
@"QTH?",
@"R",
@"SN",
@"SOS",
@"73",
@"88",
nil];
self.codeDescArray = [NSMutableArray arrayWithObjects:@"Wait",
@"Be seeing You",
@"Going off air",
@"Start Copying",
@"See you later",
@"Over",
@"I acknowledge receipt",
@"Do you acknowledge",
@"Should I wait",
@"Ready to copy",
@"Are you ready to copy?",
@"My location is ...",
@"What is your location?",
@"Roger",
@"Understood",
@"Distress message",
@"Best regards",
@"Love and kisses",
nil];
}
return self;
}
我使用委托来传回数据但我想使用核心数据将新添加的字符串保存到“presetList”& “codeDescArray”
我还创建了我的核心数据模型,我的实体名为“Morse”,并且具有两个名为“codeTitle”的字符串类型和“stringDesc”类型字符串。这些属性分别负责将数据保存到“presetList”和“codeDescArray”。我只需要了解如何将其存储在核心数据中,以便我可以使用它。有什么想法吗?
Morse.h -
#import <CoreData/CoreData.h>
@interface Morse : NSManagedObject
@property(strong,nonatomic)NSString *codeTitle;
@property(strong,nonatomic)NSString *codeDesc;
@end
答案 0 :(得分:0)
您可以通过执行以下操作来存储数组数据:
NSData *codeTitleData = [NSKeyedArchiver archivedDataWithRootObject: self.presetList];
myEntity.codeTitle = arrayData;
[self saveContext]; //Self if we are in the model class // same for other array too
您可以将数组检索为
NSMutableArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:anEntity.codeTitle];
//与其他数组相同