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

  • SEARCH
  • Home
  • 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 5845075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:22:59+00:00 2026-05-22T12:22:59+00:00

I have got a problem with converting an NSNumber value to an NSString MyPowerOnOrNot

  • 0

I have got a problem with converting an NSNumber value to an NSString

MyPowerOnOrNot is an NSNumber witch can only return a 1 or 0
and myString is an NSString..

myString = [NSString stringWithFormat:@"%d", [myPowerOnOrNot stringValue]];

NSLog(@"%@",myString);
if(myString == @"1") {
    [tablearrayPOWERSTATUS addObject:[NSString stringWithFormat:@"%@",@"ON"]];
}
else if(myString == @"0") {
    [tablearrayPOWERSTATUS addObject:[NSString stringWithFormat:@"%@",@"OFF"]];
}

What is wrong with this?

The NSLog shows 0 or 1 in the console as a string but I can’t check it if it is 1 or 0 in an if statement?

If doesn’t jump into the statements when it actually should.. I really don’t understand why this doesn’t works..
Any help would be very nice!

  • 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-05-22T12:22:59+00:00Added an answer on May 22, 2026 at 12:22 pm

    A couple of problems

    myString = [NSString stringWithFormat:@"%d", [myPowerOnOrNot stringValue]];
    

    -stringValue sent to an NSNumber gives you a reference to a string. The format specifier %d is for the C int type. What would happen in this case is that myString would contain the address of the NSString returned by [myPowerOnOrNot stringValue]. Or, on 64 bit, it would return half of that address. You could actually use [myPowerOnOrNot stringValue] directly and avoid the relatively expensive -stringWithFormat:

    if(myString == @"1")
    

    myString and @"1" are not necessarily the same object. Your condition only checks that the references are identical. In general with Objective-C you should use -isEqual: for equality of objects, but as we know these are strings, you can use -isEqualToString:

    if ([[myPowerOnOrNot stringValue] isEqualToString: @"1"])
    

    Or even better, do a numeric comparison of your NSNumber converted to an int.

    if ([myPowerOnOrNot intValue] == 1)
    

    Finally if myPowerOnOrNot is not supposed to have any value other than 0 or 1, consider having a catchall else that asserts or throws an exception just in case myPowerOnOrNot accidentally gets set wrong by a bug.

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

Sidebar

Related Questions

I have a problem while converting a string whose value is dd.mm.yyyy to DateTime
I've got a strange problem which I just can't figure out. I have currencies
I have got the following problem since the server has safe mode turned on,
I've got a problem where I have a .co.uk domain of which I am
I've got a philosophical programming problem. Let's say I have a class named Employees.
The responses I've got to this question have solved the problem I had in
I have got a problem on casting an object to one of it's base
I have got a problem with a slider. When i grab the handler, i
I have got the new problem with opening and closing form in C#. My
the problem is as follows: I have got a rendered bitmap in a byte

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.