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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:45:30+00:00 2026-06-15T10:45:30+00:00

Possible Duplicate: If a == b is false when comparing two NSString objects? In

  • 0

Possible Duplicate:
If “a == b” is false when comparing two NSString objects?

In an “if” statement I’m comparing two strings, “currentDateString” and “dateCreatedString”, to get “Today” if true and “dateCreatedString” if false. Although they should be equal when creating a new item, the if statement is returning false every time and just giving the currentDateString when I’m looking to get “today”.

- (NSString *)dateCreatedString
{
// Create a NSDateFormatter that will turn a date into a simple date string
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
NSString *dateCreatedString = [dateFormatter stringFromDate:[_detailItem dateCreated]];
return dateCreatedString;
}
- (NSString *)currentDateString
{
// Create a NSDateFormatter that will turn a date into a simple date string
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
NSString *currentDateString = [dateFormatter stringFromDate:[NSDate date]];
return currentDateString;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//places "Today" in the dateLabel if the two strings both equal today
if ([self currentDateString] == [self dateCreatedString] || [_detailItem dateCreated] == nil) {
    [_dateTxt setText:@"Today"];
}
else{
    [_dateTxt setText:[self dateCreatedString]];
}
}

Could somebody help explain why this is happening, and how to fix it?

Thanks!

  • 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-15T10:45:31+00:00Added an answer on June 15, 2026 at 10:45 am

    You should use isEqualToString to compare strings like this:

    if ([[self currentDateString] isEqualToString:[self dateCreatedString]])
    

    Using == you are comparing the pointers to the string objects, which certainly are not the same.

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

Sidebar

Related Questions

Possible Duplicate: If a == b is false when comparing two NSString objects? Simple
Possible Duplicate: Comparing two identical strings with == returns false I am having real
Possible Duplicate: comparing two variables returns false result <?php if( 32 is this a
Possible Duplicate: Is there a difference between YES/NO,TRUE/FALSE and true/false in objective-c? I have
Possible Duplicate: Javascript regex returning true.. then false.. then true.. etc var r =
Possible Duplicate: Why boolean in Java takes only true or false? Why not 1
Possible Duplicate: Python '==' vs 'is' comparing strings, 'is' fails sometimes, why? Hi. I
Possible Duplicate: Is False == 0 and True == 1 in Python an implementation
Possible Duplicate: Comparing two collections for equality I need to verify if two IEnumerable<T>
Possible Duplicate: Why can't Python handle true/false values as I expect? False = True

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.