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 8201841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:57:13+00:00 2026-06-07T06:57:13+00:00

I have an NSString , firstWord , that has the value of First. It

  • 0

I have an NSString, firstWord, that has the value of “First”. It was defined like this:

NSString *firstWord = [[NSString alloc] init];

firstWord = [textView text];

However, when I try to check its value, like so:

if (firstWord == @"First"){}

The comparison does not return true, or YES I guess in Objective-C. I know that it does have the same value as a string. So, from this I am pretty sure that the issue is that I am comparing pointers, which are not the same here, even though the strings themselves do have the same value. So how can I directly compare the strings themselves? Or maybe more efficiently, make sure the two string objects do have the same pointer, so I don’t have to the do the relatively costly string comparison?

  • 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-07T06:57:15+00:00Added an answer on June 7, 2026 at 6:57 am

    So how can I directly compare the strings themselves?

    String comparison in Cocoa is done with isEqualToString:.

    Or maybe more efficiently, make sure the two string objects do have the same pointer,

    This isn’t possible. One is a string literal, stored in the DATA section of your app’s binary; the other is on your app’s heap. In certain circumstances (creating a string using initWithString:@"literal string") you’ll end up with the same address, but you shouldn’t rely on that.

    As an aside, you don’t need to — in fact, shouldn’t, because you’re creating a leak — allocate a string before assigning the text view’s text to the pointer.

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

Sidebar

Related Questions

I HAVE STORED NSString value in NSUserDefaults, however didn't know how to retrieve that
I am new in Cocoa. I have NSString . that looks like this Attribute:
I have an NSString that holds something like this: 4434332124 How can I make
i have an NSString that is value in plist format. i download this string
I have NSString like this: @text 932. How I can return number from this
I have NSString like My name is. I want to remove text after coming
I have an NSString that I'd like to append a { at the beginning
I have an NSString declared like this : .h: @interface ViewController : UIViewController {
I have an NSString named 'you' with value This is a you string!. I
I have a NSString [WORD] that has some length [LEN]. What i need to

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.