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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:35:01+00:00 2026-05-26T09:35:01+00:00

I know that when we want to create an unknown value object we use

  • 0

I know that when we want to create an unknown value object we use id. However, I’m curious that why did Apple to choose id which decides it’s value during runtime, when every object is a subclass of NSObject. So instead of id delegate we could have used NSObject *delegate Does anyone know why? 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-05-26T09:35:02+00:00Added an answer on May 26, 2026 at 9:35 am

    id erases the type and it is equivalent to saying "this object responds to any selector visible to the translation". Of course, it is your responsibility to make sure your program is correct when you erase types (and also when you typecast them).

    If the type were NSObject, then the compiler would say "NSObject may not respond to selector" if the selector was not declared in NSObject’s interface or the protocols it adopts. In that event, you could also add a typecast to cast it to the type you expect.

    With strict/correct types, the compiler can kick in and help you out, which is great because ObjC is a very dynamic language.

    id is particularly useful when using (or building) collections types. Adding an object would not be a problem unless you defined a new root type (does not inherit from NSObject). Getting a value from the collection would require a typecast if we were to use it as something other than our base class (NSObject).

    Objective-C does not support generics – you cannot, for example, declare an NSArray of NSStrings. You can populate an NSArray with NSStrings and pass this through id for a more natural written style when type safety is not preserved (a la generics).

    So, let’s expand on this with some real code.

    Example A

    NSString * string = [array objectAtIndex:0]; // << trust me (via id)
    return [string length];
    -or-
    return [[array objectAtIndex:0] length]; // << trust me (via id)
    

    Example B

    And now let’s say id is not available and we fix all our compiler warnings because it’s the right thing to do:

    NSString * string  = (NSString*)[array objectAtIndex:0]; // << typecast == trust me
    return [string length];
    -or-
    return [(NSString*)[array objectAtIndex:0] length]; // << typecast == trust me
    

    id doesn’t decide its value at runtime, nor does any NSObject. ObjC objects don’t perform implicit promotions, they just cast the pointer through without formal promotion.

    Related to your example, I actually declare my delegates and parameters as NSObjects with protocols:

    NSObject<MONShapeDelegate>* delegate;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to know that when we want to use push notification service.From where
I know that in OOP you want every object (from a class) to be
I want to know that how voice recognition in android works? Which library it
I want to know that does apple's Push Notification Server generate new device token
I know that in java when u want to create a high performance server
I want to create my first app as a child's book. I know that
What I know is that I want to create an app running on a
I want to create a control using the jquery ui framework. I know that
I know that if I want to have requests for MyPage.aspx go to the
I know that with a large site you would want to separate footers, menus,

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.