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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:03:40+00:00 2026-06-06T11:03:40+00:00

Subtitle: why does this code work? It seems to allow comparison of NSNumber with

  • 0

Subtitle: why does this code work? It seems to allow comparison of NSNumber with NSString types via some sort of coercion. I’m trying to compare a selection from a UISegmentedControl with a previously stored value.

- (IBAction)minSegmentedControlChanged:(id)sender // MINIMUM value
{
UISegmentedControl *s1 = (UISegmentedControl *)sender;

NSMutableArray *pD = [[GameData gameData].curData valueForKey:@"persData"];

// Must make sure max >= min

NSNumber *currMax = [pD objectAtIndex:1];
NSLog(@"%@", [currMax class]); // __NSCFString ?!

int ss1 = s1.selectedSegmentIndex;
NSNumber *SS1 = [NSNumber numberWithInt:ss1 + 2];

if (SS1 >= currMax) SS1 = currMax;

NSLog(@"%@", SS1); // Answer is correct, appears to be an integer
NSLog(@"%@", [SS1 class]); // __NSCFString ?!

[pD replaceObjectAtIndex:0
              withObject:SS1];
[[GameData gameData].curData setObject:pD
                                forKey:@"persData"];
NSLog(@"%@", [[GameData gameData].curData valueForKey:@"persData"]);

}

I am particularly asking about:

NSNumber *currMax = [pD objectAtIndex:1];
NSLog(@"%@", [currMax class]); // __NSCFString ?!

which seems to return a string for a number. [[GameData gameData].curData valueForKey:@"persData"]; is initialized as follows:

         _persData = [[NSMutableArray alloc] initWithObjects:@"2", @"8", @"TWL", @"0", @"0", nil];

which is a string at element 1. So why can I ask it for an NSNumber, which reports that it is actually a __NSCFString on which I can do arithmetic comparisons on? I’ve only been at objective-c for a few months but this seems strange.

  • 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-06T11:03:41+00:00Added an answer on June 6, 2026 at 11:03 am

    Okay, let’s walk through this one step at a time.

    First of all, all of the elements in _persData are strings. Period. NSString is a class cluster, so the concrete classes of the various instances you inquire about may look weird, but that’s to support toll-free bridging and other magic that’s not relevant to this discussion.

    NSNumber *currMax = [pD objectAtIndex:1];
    

    This line is incorrect. You might think there’s some sort of coercion going on, but actually you’re just assigning an NSString * to an NSNumber *. Which is wrong, and will explode in your face at the earliest convenience. It so happens that objectAtIndex: returns an id, which is stripped of type information, so the compiler is trusting you to store it in the right kind of pointer, but that’s not enforced until you try to send a message to it.

    if (SS1 >= currMax) SS1 = currMax;
    

    This is an extremely wily comparison. SS1 is most certainly an NSNumber, but currMax is an NSString. But we’re not comparing the values of those objects. To do that, we’d use the compare: method. Instead, we’re comparing them as pointers, looking only at their addresses in memory. By some accident of implementation, SS1 seems to always reside at a higher address than currMax.

    If all of the foregoing is true, then SS1 is always of type NSString after the above line is executed, which explains why this line:

    NSLog(@"%@", [SS1 class]);
    

    Always indicates that SS1 is a string.

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

Sidebar

Related Questions

This code compiles fine without warnings but the substring does not appear in the
Every notification seems has a title, subtitle, and content. The title is from your
Visual Studio 2008 insists on indenting HTML like this: <h1> title</h1> <h2> subtitle</h2> where
I have an XML like this: <EXP> <TITLES> <SUBTITLE CL=AXT4 FL=1 NB=Text 1/> </TITLES>
Okay, so I have some code that worked fine in PHP4 but since upgrading
I have this code: db = C:\Dokumente und Einstellungen\hom\Anwendungsdaten\BayWotch4\Neuer Ordner\baywotch.db5 TextExportFile = C:\Dokumente und
Does anybody know how to get a SubTitle bar in the navigation bar, like
The code block below CreateDocument[{ TextCell[Title, Title], TextCell[Subtitle, Subtitle], TextCell[Section 1, Section], TextCell[Section 1.1,
I'm using a try-catch block in the following Actionscript 3 code: try { this._subtitle
Does anyone have any idea what is wrong with this create statement for mysql?

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.