0

Possible Duplicate:
Understanding NSString comparison in Objective-C

Header file:

@property (nonatomic, strong) NSString *pid;
@property (nonatomic, strong) NSString *name;

Coredata NSString stored:

[newPref setValue: @"0" forKey:@"pid"];  //correctly show in DB & NSLog
[newPref setValue: @"Sales" forKey:@"name"];

After later retrieving, evaluation fails:

if(preference.pid == @"0")

Debugger says:

_pid = (NSSting *) 0x... @"o\xee\"
_name = (NSString *) )x0.. @<variable is not NSString>

Is my storing of the NSString incorrect, or is my evaluation wrong? Note: The Coredata model is type string also.

Community
  • 1
  • 1
llBuckshotll
  • 119
  • 1
  • 9
  • Its hard to say if you might have an error somewhere else. But you should generally compare strings with isEqualToString: – artey Jan 04 '13 at 21:43
  • By 'Header file:' do you mean your NSManagedObject class? It should not contain @property values. – jer-k Jan 04 '13 at 21:43
  • http://stackoverflow.com/questions/3703554/understanding-nsstring-comparison-in-objective-c – Augie Jan 04 '13 at 21:44
  • @TheJer Why wouldn't NSManagedObject classes contain property values? It's perfectly reasonable/expected for them to have many. – Matt C. Jan 04 '13 at 21:59
  • @MechIntel Whoops, I was thinking of synthesize vs dynamic and for some reason was thinking they were declared as dynamic in the .h file also. – jer-k Jan 04 '13 at 22:47

1 Answers1

2

In your code, you are comparing the objects, but if you want to compare strings, it should be

if ([preference.pid isEqualToString:@"0"])
SAE
  • 1,609
  • 2
  • 18
  • 22