0
votes

I have 2 NSMutableArrays in my project and was told that since Core Data doesn't support NSMutableArray that I would have to archive and unarchive it with NSKeyedArchiver to be able to save it to Core Data. I've implemented an NSFetchResultsController for my tableview, how would I go about saving the NSMutableArray in the the NSKeyedArchiver and then using that in Core Data? I'll post some code below of my arrays and the NSKeyArchiver.

- (instancetype)init {
    self = [super init];
    if (self) {
    self.nameList = [NSMutableArray arrayWithObjects:@"1",
                                                   @"2",
                                                   @"3",
                                                   @"4",
                                                   @"5",
                                                   nil];


   self.descArray = [NSMutableArray  arrayWithObjects:@"desc1",
                                                      @"desc2",
                                                      @"desc3",
                                                      @"desc4",
                                                      @"desc5",
                                                      nil];
                   }
    return self;
}

// How arrays are archived
NSData *titleData = [NSKeyedArchiver archivedDataWithRootObject: self.nameList];

.... //Not sure what to do with the archived data

NSData *descData = [NSKeyedArchiver archivedDataWithRootObject: self.descArray];

....

What would I do with the two arrays now that they are archived? How would I be able to add to them later?

My Core Data model is simple it is an entity called "Data" and has 2 attributes of type string called "title" and "desc". The 2 attributes are used to store the arrays.

My hope for this project is to allow the user to add new objects to the tableview, on top of the existing data that make up the cells already, and I want this done in Core Data. I'm aware of NSFetchResultController but am having trouble bringing this all together to get it to work, any help to steer me in the right direction is welcomed

1
It looks more like you should have a Core Data entity with name and description attributes and then create a number of these objects in Core DataPaulw11

1 Answers

0
votes

You can save immutable data in core data. U can go with mutable to immutable after that you can by NSKeyedArchiver. Same things with NSUserDefaults.