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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:40:52+00:00 2026-06-02T05:40:52+00:00

I am reading: http://cocoacast.com/?q=node/103 I came across this method in the above page: -(void)foo

  • 0

I am reading: http://cocoacast.com/?q=node/103

I came across this method in the above page:

-(void)foo
   {
    self->iVar = 5; //legal because we are referencing a member variable
iVar = r; // illegal because we are referencing a readonly property
     }    

I then created a project in Xcode.

Test0.h

#import <Foundation/Foundation.h>

@interface Test0 : NSObject
{
@private int iVar;
 }
 @property (readonly, assign) int iVar;
 - (void) foo;
 @end

Test0.m

#import "Test0.h"

@implementation Test0
@synthesize iVar;

 - (void) foo
{
iVar = 5;
 }
  @end      

main.m

  #import <Foundation/Foundation.h>
  #import "Test0.h"
  int main(int argc, const char * argv[])
  {

  @autoreleasepool {
    Test0 *t1 = [[Test0 alloc] init];
    [t1 foo];
    NSLog(@"%d", t1.iVar);
    }
    return 0;
     }

The result in Console is 5.

My questions:

  1. The web page mentioned above uses
    self->iVar = 5
    I have used iVar = 5

What difference does it make?

  1. The web page mentioned above says
    iVar = r; // illegal because we are referencing a readonly property

Is iVar = 5 (which I have used) not same as iVar = r ?
How is it not illegal?

  • 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-02T05:40:54+00:00Added an answer on June 2, 2026 at 5:40 am

    how does readonly property work?

    The compiler simply does not generate or verify the existence of the setter. It will generate the getter, and that property may be backed by an ivar. As well, the setter is not declared in the class interface.

    self->iVar = r;

    vs

    iVar = r;

    What difference does it make?

    None. They are identical. They are both direct assignment of the ivar. It’s similar to other languages, when adding a superfluous scope resolution (e.g. this->).

    The difference is when you attempt to use the setter method (e.g. self.prop = val or [self setProp:val];). In this case, the compiler will emit a warning and the runtime would throw an exception (unless you or a subclass defined the setter yourself).

    The web page mentioned above says iVar = r; // illegal because we are referencing a readonly property.

    That’s wrong. Direct access to the ivar of a readonly property is fine if the ivar exists. You don’t see an error in this case because you’re accessing the ivar directly, rather than using the setter.


    Other issues:

    • The article incorrectly states atomics are ‘mutexed’.
    • The article incorrectly states atomic properties guarantee thread safety.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I was reading http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html , and came across this: type __sync_and_and_fetch (type *ptr,
After reading this: http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#how-to-use-it I came to the conclusion that it is not valid
While reading http://en.wikipedia.org/wiki/C_preprocessor#Multiple_evaluation_of_side_effects , I came across this example: \#define max(a,b) \ ({ typeof
Reading this article http://support.microsoft.com/kb/813878 I have a question: Where can I get ipseccmd.exe for
just was reading this article http://highscalability.com/blog/2010/3/23/digg-4000-performance-increase-by-sorting-in-php-rather-than.html And found this nice article http://wiki.apache.org/cassandra/DataModel I just
After reading http://gbif.blogspot.com/2011/01/setting-up-hadoop-cluster-part-1-manual.html we came to the conclusion our 6-nodes hadoop cluster could use
I was reading this http://developer.android.com/guide/topics/wireless/bluetooth.html#QueryingPairedDevices which is allot of help on how to pair,connect
Hello Haskellers and Haskellettes, when reading http://learnyouahaskell.com/ a friend of mine came up with
I was just reading http://api.jquery.com/event.stopPropagation/ Since the .live() method handles events once they have
Not sure if I am doing this right. Reading: http://devcenter.heroku.com/articles/cron#frequently-asked-questions If I have cron

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.