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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:26:23+00:00 2026-05-13T16:26:23+00:00

In Objective-C, why [object doSomething] ? Wouldn’t it be [*object doSomething] since you’re calling

  • 0

In Objective-C, why [object doSomething]? Wouldn’t it be [*object doSomething] since you’re calling a method on the object?, which means you should dereference the pointer?

  • 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-13T16:26:24+00:00Added an answer on May 13, 2026 at 4:26 pm

    The answer harkens back to the C roots of Objective-C. Objective-C was originally written as a compiler pre-processor for C. That is, Objective-C wasn’t compiled so much as it was transformed into straight C and then compiled.

    Start with the definition of the type id. It is declared as:

    typedef struct objc_object {
        Class isa;
    } *id;
    

    That is, an id is a pointer to a structure whose first field is of type Class (which, itself, is a pointer to a structure that defines a class). Now, consider NSObject:

    @interface NSObject <NSObject> {
        Class   isa;
    }
    

    Note that the layout of NSObject and the layout of the type pointed to by id are identical. That is because, in reality, an instance of an Objective-C object is really just a pointer to a structure whose first field — always a pointer — points to the class that contains the methods for that instance (along with some other metadata).

    When you subclass NSObject and add some instance variables you are, for all intents and purposes, simply creating a new C structure that contains your instance variables as slots in that structure concatenated on the slots for the instance variables for all superclasses. (The modern runtime works slightly differently so that a superclass can have ivars appended without requiring all subclasses to be recompiled).

    Now, consider the difference between these two variables:

    NSRect foo;
    NSRect *bar;
    

    (NSRect being a simple C structure — no ObjC involved). foo is created with the storage on the stack. It will not survive once the stack frame is closed, but you also don’t have to free any memory. bar is a reference to an NSRect structure that was, most likely, created on the heap using malloc().

    If you try to say:

    NSArray foo;
    NSArray *bar;
    

    The compiler will complain about the first, saying something along the lines of stack based objects are not allowed in Objective-C. In other words, all Objective-C objects must be allocated from the heap (more or less– there are one or two exceptions, but they are comparatively esoteric to this discussion) and, as a result, you always refer to an object through the address of said object on the heap; you are always working with pointers to objects (and the id type really is just a pointer to any old object).

    Getting back to the C preprocessor roots of the language, you can translate every method call to an equivalent line of C. For example, the following two lines of code are identical:

    [myArray objectAtIndex: 42];
    objc_msgSend(myArray, @selector(objectAtIndex:), 42);
    

    Similarly, a method declared like this:

    - (id) objectAtIndex: (NSUInteger) a;
    

    Is equivalent to C function declared like this:

    id object_at_index(id self, SEL _cmd, NSUInteger a);
    

    And, looking at objc_msgSend(), the first argument is declared to be of type id:

    OBJC_EXPORT id objc_msgSend(id self, SEL op, ...);
    

    And that is exactly why you don’t use *foo as the target of a method call. Do the translation through the above forms — the call to [myArray objectAtIndex: 42] is translated to the above C function call which then must call something with the equivalent C function call declaration (all dressed up in method syntax).

    The object reference is carried through because it gives the messenger — objc_msgSend() access to the class to then find the method implementation — as well as that reference then becoming the first parameter — the self — of the method that is eventually executed.

    If you really want to go deep, start here. But don’t bother until you have fully grokked this.

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

Sidebar

Ask A Question

Stats

  • Questions 378k
  • Answers 378k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer if you mean #temp1 is the div showing, .hide() then… May 14, 2026 at 9:16 pm
  • Editorial Team
    Editorial Team added an answer Take a look at the things you can do with… May 14, 2026 at 9:16 pm
  • Editorial Team
    Editorial Team added an answer You should periodically move log rows out to a historical… May 14, 2026 at 9:16 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.