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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:59:04+00:00 2026-05-29T10:59:04+00:00

Since recent runtimes in iOS, we are able to define properties that will generate

  • 0

Since recent runtimes in iOS, we are able to define properties that will generate accessors for instance variables. From what I understand, it is not mandatory to declare the instance variable used since it will be automatically done for us.

For example, if I write:

@interface MyFirstClass
@property (readonly, nonatomic) int size; 
@end

and in the .m

@implementation MyFirstClass
@synthesize size;
@end

Then an instance variable named “size” will be added for me and a method called “-(int)size” will be implemented.

The problem is that when I create a second class MySecondClass which is a subclass of MyFirstClass, it seems that I can’t access the instance variable size within this subclass:

@interface MySecondClass : MyFirstClass
@end

@implementation MySecondClass
- (id)init {
    if (self = [super init]) {
        size = 10;  // this yields and error
    }
    return self;
}
@end

Are the automatically created instance variables private? Is there a possibility to set them as protected so I can access them in subclasses?
I know there is the possibility to declare the instance variable myself, but I’m just wondering…

With a superclass like this it works: (Is it because it’s expressly declared as protected?)

@interface MyFirstClass {
    int size;  // defined expressly and used as @protected
}
@property (readonly, nonatomic) int size;
@end

Thank you for your help!!
Nicolas.

  • 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-29T10:59:05+00:00Added an answer on May 29, 2026 at 10:59 am

    Any instance variable not declared in the main interface is automatically private, and this cannot be overridden. If you try to use a scope modifier when defining instance variables in the implementation, you will get an error that the specification is inconsistent.

    The reason for this is that there is usually only one class per implementation file, which means the compiler doesn’t know about the instance variable when compiling other classes. If you have multiple classes in the same file, the compiler could know about it, but you still aren’t allowed to override the scope. Possible reasons in this case could be for consistency, or just so the compiler doesn’t have to look in so many places for instance variables.

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

Sidebar

Related Questions

I've defined a listview in my recent project and realized that I will be
I'm trying to write a query that will pull back the two most recent
Since Graduating from a very small school in 2006 with a badly shaped &
Since I switched to CEDET as shipped with recent emacs release (23.2), CEDET does
In a recent question of mine I learned that if there are more than
As just stated in a recent question and answer , you can't inherit from
Following on from my recent question on Large, Complex Objects as a Web Service
There's an error message I can't understand since I don't see where my code
A recent question about string literals in .NET caught my eye. I know that
I have a MySQL 5 database that is updated every 5 minutes from a

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.