Reputation: 3258
I'm currently trying to set up my entity by filling in the required attributes. I am doing this by parsing an XML response and assigning the attributes as they come up. The issue that I am running into is that I have what seems to be a type mismatch that results in my attribute set function throwing an "incorrect selector sent to function" error. I have gone into the debugger and noticed that always before assigning to my custEntity.name attribute, my type seems to be of NSCFString instead of NSString. I have done some searching as well as some tests and attempted fixes of my own but have been unable to get anywhere. Here is some relevant code and its effects.
Auto Generated and Combined into one file with my other entity definition, DataModelObject.h:
@interface Checkpoint : NSManagedObject {
@private
}
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * lat;
@property (nonatomic, retain) NSNumber * lon;
@property (nonatomic, retain) NSManagedObject * myRoute;
@end
DataModelObject.m
@implementation Checkpoint
@dynamic name;
@dynamic lat;
@dynamic lon;
@dynamic myRoute;
@end
What my current code looks like as a result of a suggestion to someone else with a somewhat similar problem elsewhere:
NSString *chkptName = [attributeDict objectForKey:@"name"];
checkpoint.name = [[NSString stringWithString:chkptName] stringValue];
This seems like some serious overkill to me, though I'm new to Objective-c and iPhone development so I dont know, it may be necessary, in any case this does not work. Before the execution of the second line the value of chkptName is the correct, human readable string that I would like to assign. In theory, if I understand the second line correctly, I simply re-declare an NSString with the value of ckptName, and the read out the actual value of it again with stringValue, which should be the same as getting the value of chkptName. However its in the second line that my app crashes with sigAbrt and when I attempt to check the values of my variable it shows that its of type NSCFString, with an invalid summary for the value. At this point I am at a loss on how to fix this. I have correctly modified entity attributes before and have not run into this problem before.
It is probably also worth noting that I started this out much simpler:
checkpoint.name = [attributeDict objectForKey:@"name"];
But this yielded the same sigAbrt and incorrect selector error.
Edit: Full Error as requested:
2011-08-02 07:25:00.544 MyApp[16011:207] -[NSCFString stringValue]: unrecognized selector sent to instance 0x5c174e0 2011-08-02 07:25:00.545 MyApp[16011:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString stringValue]: unrecognized selector sent to instance 0x5c174e0'
Edit2: Debugger Output:
(gdb) po checkpoint
<Checkpoint: 0x5a30730> (entity: (null); id: (null) ; data: {})
(gdb) po [checkpoint class]
Checkpoint
(gdb) po [checkpoint entity]
Can't print the description of a NIL object.
Any clarification that you can provide is much appreciated, if there is also some relevant code that I missed please ask and I will be happy to provide it if possible. Thanks!
-Karoly
Upvotes: 2
Views: 706
Reputation: 1141
So it seems that the question has already been answered, but maybe for future reference:
If you get an error like this:
2011-08-02 07:25:00.544 MyApp[16011:207] -[NSCFString stringValue]: unrecognized selector sent to instance
It's pretty useful to really look at what it's saying:
unrecognized selector sent to instance
means that an object has received a message that it cannot respond to or doesn't know how to.
-[NSCFString stringValue]
shows you what message was sent (stringValue
) and which object it was sent to (NSCFString
).
From the message in the error we see that the error most probably happened when you called
checkpoint.name = [[NSString stringWithString:chkptName] stringValue];
Since that seems to be the only place where you call the message stringValue
on an object (from what you've posted). And NSCFString
is simply a subclass of NSString
.
So you can't call stringValue
on an NSString
(which makes sense too). Just for clarification, but as I've read the issue has already been resolved. :)
Upvotes: 1
Reputation: 36752
I think you should take a careful look and verify that your checkpoint
variable really is an instance of the Checkpoint
class.
po checkpoint
.po [checkpoint entity]
.Upvotes: 1