문제

I have some entities in core data, and they are all sub classes of a super class which has a NSDate attribute,

and all others works well when I save them,

but one of them would seemingly probabilisticly crash when I save it,

and I found the reason is about its NSDate attribute inherited from its super Class,

when I set the date value for the NSDate attribute, it crashes and log out this:

2012-02-10 00:24:34.474 EasyWallet[37772:707] -[__NSDate managedObjectContext]: unrecognized 
selector sent to instance 0xdc54c30
2012-02-10 00:24:34.483 EasyWallet[37772:707] *** Terminating app due to uncaught exception 
'NSInvalidArgumentException', reason: '-[__NSDate managedObjectContext]: unrecognized 
selector sent to instance 0xdc54c30'
*** First throw call stack:
(0x344268bf 0x346761e5 0x34429acb 0x34428945 0x34383680 0x32f8811b 0x32f8904b 0x32f8aeb5   
0x32f83161 0x32f7e8cf 0x3c507 0x34380435 0x377ea9eb 0x377ea9a7 0x377ea985 0x377ea6f5 
0x377eb02d 0x377e950f 0x377e8f01 0x377cf4ed 0x377ced2d 0x30c01df3 0x343fa553 0x343fa4f5 
0x343f9343 0x3437c4dd 0x3437c3a5 0x30c00fcd 0x377fd743 0x29b1 0x2970)
terminate called throwing an exception(gdb) 

and here is my code for saving these attributes

... // get keys
 self.rowKeys = [NSMutableArray arrayWithObjects:@"personName",@"amount",@"incomingAccount",
                    @"date",@"returnDate",@"isReturned",@"memo",nil];
... // saving
for (int i = 0; i < [self.rowKeys count]; i++) {
    NSLog(@"%d: %@",i,[rowValues valueForKey:key(i)]);
    [newMo setValue:[self.rowValues valueForKey:key(i)] forKey:key(i)];
}

the key(i) here is a macro define:

#define key(X) [rowKeys objectAtIndex:(X)]

and the date was printed out like this, with no surprise.

2012-02-10 16:00:00 +0000

when it comes to save "date" attribute, it crashes, but fewer times it just passed.

I got that date from a UIDatePicker, and I've checked my codes finding nothing wrong I think.

Really need some help!

Thanks a lot!

도움이 되었습니까?

해결책

I've fixed it.

The problem is that I made a silly mistake of sending some NSDate method to a non-NSDate ojbect, in some very secret place.

Just pay attention to your codes, especially confusing parts.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top