0
votes

In core data I've setup a simple entity called GolferEntity that contains simply a golferObject (transformable type) and playerId (string).

- (void)addOrUpdateGolfer:(GolferObject *)feedObj
{   
    NSLog(@"In add or update Feed");

// get reference to local (stored) golfer item, create it if needed
Golfer *localGolfer = [self golferForId:[feedObj PlayerId]];
if (localGolfer == nil) {
    localGolfer = (Golfer *)[NSEntityDescription insertNewObjectForEntityForName:@"GolferEntity" inManagedObjectContext:[self managedObjectContext]];
    [localGolfer setPlayerId:[feedObj PlayerId]];
}

// set folder fields
[localGolfer setGolferObj:feedObj];

// apply update
NSError *error;
if (![managedObjectContext save:&error]) {
    NSLog(@"%@", [error localizedDescription]);
    //      return nil;
}
NSLog(@"successfully saved user: %@", [feedObj PlayerId]);
//return localFolder;
}

The code is giving me a runtime error which reads: * -[NSKeyedArchiver dealloc]: warning: NSKeyedArchiver deallocated without having had -finishEncoding called on it. * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GolferObject encodeWithCoder:]: unrecognized selector sent to instance 0x4b7520'

-- No where in my code have i alloc'd NSKeyedArchiver so I'm assuming this is something that done by core data? also my GolferObject does not have an encodeWithCoder method? I do not know where this is coming from?

1
Are you getting a backtrace to the -[NSKeyedArchiver dealloc] warning? Set a breakpoint in Xcode on -[NSKeyedArchiver dealloc] so you can see where the call originates. - bneely
I haven't written "NSKeyedArchiver" anywhere in my code. That's the issue. I don't have the slightest clue as to what/where this issue is coming from. I'd architected the entity with the assumption that a transformable type attribute can contain a custom object. - propstm
Right, it sounds like the NSKeyedArchiver is being managed by a class or framework you are using. Although you're not directly responsible for the NSKeyedArchiver object, your code may have an error that is being manifested in this unhelpful way. If you set the breakpoint and get a backtrace, this can serve as a starting point for your debugging. - bneely
Did you get this resolved? I'm having the same issue. - Imran
Yes, I needed to encode before submitting to my custom object in CoreData. I needed to use the - (void)encodeWithCoder:(NSCoder *)encoder; and - (id)initWithCoder:(NSCoder *)decoder; methods. - propstm

1 Answers

1
votes

I needed to encode before submitting to my custom object in CoreData. I needed to use the - (void)encodeWithCoder:(NSCoder *)encoder; and - (id)initWithCoder:(NSCoder *)decoder; methods.