Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8998355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:00:54+00:00 2026-06-16T00:00:54+00:00

Possible Duplicate: Compare 2 string in objective-C i try to compare equality between 2

  • 0

Possible Duplicate:
Compare 2 string in objective-C

i try to compare equality between 2 NSString …

the 1st one is stored in the shared user defaults and the 2nd one is entered by the user thru a NSTextField …

is here is a little bit of my code (Xcode 4.5.2 Mac OS 10.7) …

1st the AppDelegate.h :

@interface AppDelegate : NSObject <NSApplicationDelegate>{

    NSUserDefaults *administratifPref;

    ...

    IBOutlet NSTextField *champProtection;

    ...
}

...

- (IBAction)poursuivre:(id) sender;

...

@end

and here the AppDelegate.m :

- (IBAction)poursuivre:(id)sender {

if([champProtection stringValue] == [champProtection stringValue]){
    ...
    ...
    }

}

my question is : why the condition “if” is never verified ?!

i get no issues, no crash …

i did add 2 NSLog :

- (IBAction)poursuivre:(id)sender {


NSLog([champProtection stringValue]);
NSLog([administratifPref valueForKey:@"motdepasse"]);


if([champProtection stringValue] == [champProtection stringValue]){
    ...
    ...
    }

}

and the returned values are the same 🙁

the only solution i found is doing :

- (IBAction)poursuivre:(id)sender {

BOOL result = [[champProtection stringValue] isEqualToString:[administratifPref valueForKey:@"motdepasse"]];
if(result == YES) {
    ...
    ...
    }

}

so …
can anyone explain me the difference between these 2 ways of coding, that seem to be soooooo different ? (but that really seem the same for a newbee like me, who trust people who say that Cocoa is very simple ^^)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:00:55+00:00Added an answer on June 16, 2026 at 12:00 am

    Objective-C is a strict superset of C. It adds objects by placing them behind opaque pointers — the asterisk in all Objective-C object declarations (typedefs aside) means that the actual thing you’re holding is a pointer to an object, i.e. its address in memory, rather than the object itself.

    When you perform == on two pointers you ask ‘do they both reference the same location in memory?’. If they do then both refer to the same object, so amongst other properties both pointers reference something of the same value.

    When you use isEqual: (or one of its more specific siblings) you ask ‘regardless of their location, do these two objects have the same value?’, which is quite a different thing semantically.

    So the two things are quite different and in your case your description of the behaviour you want means you want to use the latter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Differences in string compare methods in C# Is there any difference between
Possible Duplicate: Understanding NSString comparison in Objective-C I want to compare an int and
Possible Duplicate: Understanding NSString comparison in Objective-C Was just reading up about equality vs
Possible Duplicate: How does Python compare string and int? Can any one explain the
Possible Duplicate: How do I compare strings in objective c? Objective-C If statement? When
Possible Duplicate: Differences in string compare methods in C# In .NET there are many
Possible Duplicate: How does Python compare string and int? An intern was just asking
Possible Duplicate: How do I compare strings in Java? String s1 = andrei; String
Possible Duplicate: Understanding NSString comparison in Objective-C I'v encountered strange things in objective-c, I'm
Possible Duplicate: How to compare strings I want to Compare to registry string values

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.