Note that there are some explanatory texts on larger screens.

plurals
  1. POCore Data saving a NS(Mutable)Array fails
    primarykey
    data
    text
    <p>I'm having a problem with Core Data. I have two Entities (Article and Manufacturer) (one containing a transformable attribute which is an array of the other entity). Everything's working fine till I try to add the array to the NSManagedObject. Here's some code:</p> <pre><code>@implementation HASArticleInitializer - (void)initialize:(NSArray *)initArray { //Alloc and init some local variables NSMutableArray *articleEntitiesArray = [NSMutableArray alloc] init]; for (NSInteger pageIndex = 1; pageIndex &lt;= pageCount; pageIndex++) { //Parsing the website //For-loop for every object on every page for (NSInteger object = 0; object &lt; [articleNumbersOnOnePageArray count]; object++) { //Doing other string manipulation and parsing stuff NSManagedObject *newArticleEntry = [NSEntityDescription insertNewObjectForEntityForName:@"Article"inManagedObjectContext:context]; [newArticleEntry setValue:[NSString stringWithFormat:@"%@_%@", manufacturerNumber, articleNumber] forKey:@"number"]; [newArticleEntry setValue:articleTextComplete forKey:@"text"]; [newArticleEntry setValue:articleStatus forKey:@"status"]; [newArticleEntry setValue:manufacturerName forKey:@"manufacturerName"]; [newArticleEntry setValue:manufacturerNumber forKey:@"manufacturerID"]; [articleEntitiesArray addObject:newArticleEntry]; } } NSManagedObject *newManufacturerEntry = [NSEntityDescription insertNewObjectForEntityForName:@"Manufacturer" inManagedObjectContext:context]; //Encoding the NSArray and setting the entity attribute to Binary Data doesn't work neither //NSData *arrayData = [NSKeyedArchiver archivedDataWithRootObject:articleEntitiesArray]; [newManufacturerEntry setValue:manufacturerName forKey:@"name"]; [newManufacturerEntry setValue:manufacturerNumber forKey:@"manufacturerID"]; [newManufacturerEntry setValue:manufacturerCount forKey:@"count"]; [newManufacturerEntry setValue:articleEntitiesArray forKey:@"articles"]; NSLog(@"%@", articleEntitiesArray); } @end </code></pre> <p>I tried everything I thought it could or couldn't help, I've really spend days on this, but I always get the following error when the AppDelegate's <code>- (IBAction)saveAction:(id)sender</code> method is called:</p> <pre><code>[15836:a057] -[NSManagedObject encodeWithCoder:]: unrecognized selector sent to instance 0x1001896e0 [15836:a057] An uncaught exception was raised [15836:a057] -[NSManagedObject encodeWithCoder:]: unrecognized selector sent to instance 0x1001896e0 [15836:a057] ( 0 CoreFoundation 0x00007fff8dc94716 __exceptionPreprocess + 198 1 libobjc.A.dylib 0x00007fff8bfe6470 objc_exception_throw + 43 2 CoreFoundation 0x00007fff8dd2ad5a -[NSObject(NSObject) doesNotRecognizeSelector:] + 186 3 CoreFoundation 0x00007fff8dc82c3e ___forwarding___ + 414 4 CoreFoundation 0x00007fff8dc82a28 _CF_forwarding_prep_0 + 232 5 Foundation 0x00007fff86931401 _encodeObject + 1163 6 Foundation 0x00007fff869323cc -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 410 7 Foundation 0x00007fff869320c9 -[NSArray(NSArray) encodeWithCoder:] + 473 8 Foundation 0x00007fff86931401 _encodeObject + 1163 9 Foundation 0x00007fff869358f9 +[NSKeyedArchiver archivedDataWithRootObject:] + 182 10 iLoadPix 0x0000000100003c21 -[HASArticleInitializer initialize:] + 3793 11 Foundation 0x00007fff86926842 __NSThread__main__ + 1345 12 libsystem_c.dylib 0x00007fff88553782 _pthread_start + 327 13 libsystem_c.dylib 0x00007fff885401c1 thread_start + 13 </code></pre> <p>Core Data Model: <a href="http://imgur.com/lxAE9,p29CM#1" rel="nofollow">Entity 1</a> <a href="http://imgur.com/lxAE9,p29CM#0" rel="nofollow">Entity 2</a></p> <p>As I said, everything works fine if I don't save the array, the NSLog is correct, too. If it matters I use NSThreads (but I don't think so because everything else works just fine) :-(</p> <p>Please help me! Thanks so much in advance! :-(</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload