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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:15:10+00:00 2026-05-26T12:15:10+00:00

So in some of the codes I see, they access an objects ivar directly

  • 0

So in some of the codes I see, they access an objects ivar directly instead of using accessors . What are the advantages of using them instead of accessors?

So how would this

thing = object->ivar 

differ from this?

thing = object.ivar

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-26T12:15:11+00:00Added an answer on May 26, 2026 at 12:15 pm

    First let me say, I totally loathe the Objective-C dot notation. It sacrifices understandability for brevity and that is a bad thing. In fact, the other two answers here both show evidence of the kind of confusion dot notation introduces.

    Having got the rant out of the way, I’ll now try to answer the question.

    Under the hood, Objective-C objects are implemented as pointers to C structs. This is why

    obj->ivar
    

    sometimes works. Given that it’s a C struct

    (*obj).ivar

    should also work exactly as you would expect for C. Having said that, you can make ivars private or protected, in which case using the above outside a scope where they are visible will cause a compiler error.

    The dot operator when applied to an Objective-C object (which is a pointer don’t forget) has a totally different meaning. It’s syntactic sugar for sending an accessor message to the object meaning that:

    foo = obj.property;
    obj.property = foo;
    

    is identical in effect to

    foo = [obj property];
    [obj setProperty: foo];
    

    That is all there is to dot notation. If you go through your code changing all instances of the first form to instances of the second form, you have done everything the compiler does wrt dot notation.

    In particular

    • you do not need a declared @property to use dot notation. You can declare the set and get accessors in the traditional way as Objective C methods, although it is definitely best practice to use @property declarations for things that are logically properties.
    • you do not need a backing instance variable. There’s no reason why your getters and setters can’t calculate values.

    Given the above, the major difference between obj->ivar and obj.ivar is that the former modifies the ivar directly and latter invokes an accessor, this means that the latter can do any memory management stuff needed (retains, releases, copies etc) and can also invoke key value observing.

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

Sidebar

Related Questions

Problem I am making a project using Q_OBJECT and Q_PROPERTY to access some objects
I have some code that is using SyncEnumerator. As you can see here ,
So I'm looking through some code, and I see this: class whatever { public:
Looking some frameworks like Code Igniter I see they use a defined check on
I need some help in using objects from Core Data with GCD; I seem
I see some code where the author has truncated a temp table immediately before
When reading some FreeBSD source code (See: radix.h lines 158-173), I found variable declarations
I have an example of some code that I see often in websites that
In some code I've inherited, I see frequent use of size_t with the std
Basically I have some code to check a specific directory to see if an

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.