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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:06:38+00:00 2026-06-10T16:06:38+00:00

Latest version of Objective-C and XCode (4.4). I have a code snippet and I

  • 0

Latest version of Objective-C and XCode (4.4).

I have a code snippet and I cannot understand why I’m able to use some lines, let me explain :

// For understanding purpose : (NSMutableArray*)_programStack

id l_topItemOnStack = [_programStack lastObject];
if([l_topItemOnStack isKindOfClass:[NSNumber class]])
{
    return [l_topItemOnStack doubleValue];
}

My question : since my l_topItemOnStack is of type id and I didn’t cast it into a NSNumber, how am i able to use the [l_topItemOnStack doubleValue].

I guessed that I had to cast it to NSNumber first to access the NSNumber methods…

What am I missing here ?

  • 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-10T16:06:40+00:00Added an answer on June 10, 2026 at 4:06 pm

    Because Objective-C is a dynamic language, the message names and their declarations are just hints for the compiler – the actual message lookup and sending occurs at runtime. So even if the compiler doesn’t know your object responds to the doubleValue message, it’s still able to make your call into

    return objc_msgSend(l_topItemOnStack, @selector(doubleValue));
    

    as usually.

    Furthermore, the compiler looks up all the selectors that are declared anywhere in the included headers, and tries to find the best match using the actual context – here doubleValue is a unique name – it’s declared on NSNumber only, so the compiler assumes that your object is indeed an NSNumber.

    If you really want to avoid this, either cast the object when you call the method or initially declare it as an NSNumber.

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

Sidebar

Related Questions

I use MinGW latest version to compile the following code. I get the folowing
I have an application I am updating to the latest version of Xcode and
With the latest version of Xcode from Apple, I have the following problem. Upon
I'm writing an iPhone app in Objective-C with Xcode and I have some Lua
I have installed the latest version of netbeans and its working.. I have opened
I am using the latest version of protobuf-net with VS2008 integration. I have created
The latest version of Apple's UICatalog example application includes zero code in the TextFieldController
I've downloaded latest version of Xcode and iOS SDK: iOS 5.1 beta 3 and
I have downloaded the latest version of JFreeChart (1.0.14) and want to start using
The latest version of XCode supports reference counting. However many older libraries are not

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.