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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:36:05+00:00 2026-05-30T10:36:05+00:00

What is the best way to make an iVar writeable by its owning class,

  • 0

What is the best way to make an iVar writeable by its owning class, but readonly by other classes?

Is there more than one way?

The only way I can think of is to set a @property (readonly) for the iVar, but not use dot notation inside the owning class (which I’m guessing wouldn’t work with readonly), and in the owning class just reference it directly, without dot notation, then in other class, reference it with dot notation.

But I’m curious if there are other methods.

  • 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-30T10:36:07+00:00Added an answer on May 30, 2026 at 10:36 am

    You can make a property read/write just for the implementation. You do this using a class extension, or anonymous category, in your implementation. Easier to demonstrate so, for example, in your .h:

    @interface MyClass
    
    @property (readonly) NSInteger age;
    ...
    
    @end
    

    and in your .m:

    @interface MyClass () // class extension/anonymous category for private methods & properties
                          // implementation of these go in main @implementation
    
    @property (readwrite) NSInteger age;
    ...
    
    @end
    
    @implementation MyClass
    
    @synthesize age;
    ...
    
    @end
    

    Now you can use the property within your class read/write and from outside as read-only.

    You do the same for private methods.

    [Note: This is Objective-C so the above isn’t bullet proof – there are ways around it to call the properties setter – but the compiler will flag errors which assign to the property from outside the class.]

    After comments:

    [Note 2: an anonymous category/class extension is very similar to a named category. The former must be implemented in the main implementation, the latter may be implemented in an @implementation classname (categoryname) or in the main implementation. Furthermore only the main interface, the interface for a class extension/anonymous category, and the main implementation may declare instance variables; interfaces and implementations for named categories may not. Properties may be declared in both anonymous and named categories, however they may only be synthesized in the main implementation and not in named category implementations. This note is correct at press time, some of these features have changed as Objective-C/Xcode develops.]

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

Sidebar

Related Questions

Hopefully this explanation will make sense, but what is the best way (if it
What is the best way to make a variable accessable to all classes. For
What is the best way to make a class property Write Once, Read Many
Wondering what the best way to make this more efficient, perhaps with jQuery. I
Is there a way to make sure Magento calls secure urls when its in
What is the best way to make more room (increase width of the bitmap)
what's the best way to make communications between page widgets residing on differents ViewPart?
What is the best way to make an HTTP GET request in Ruby with
What is the best way to make sure that all the environment variables I
What is the best way to make my Qt Ruby application into an executable

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.