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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:33:35+00:00 2026-05-29T22:33:35+00:00

If I have this class defined, how do I access the someObject property in

  • 0

If I have this class defined, how do I access the someObject property in subclasses without compiler errors?

@interface MyBaseClass
  // someObject property not declared here because I want it to be scoped 
  // protected. Only this class instance and subclass instances should be
  // able to see the someObject property.
@end

// This is a private interface extension...properties declared here
// won't be visible to subclasses. However, I don't see any way to 
// declare protected properties...
@interface MyBaseClass (private)
   @property (nonatomic, readwrite, retain) NSObject *someObject;
@end

@interface MySubclass : MyBaseClass 
@end

@implementation MySubclass

- (id) init {
    // Try to do something with the super classes' someObject property. 
    // Always throws compile errors.

    // Semantic Issue: Property 'someObject' not found 
    // object of type 'MySubclass *'
    self.someObject = nil; 

}
@end

I’m obviously not understanding how inheritance works in objective-c. Could someone enlighten me?

  • 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-29T22:33:37+00:00Added an answer on May 29, 2026 at 10:33 pm

    The solution you’re after is to declare the MyBaseClass private property in a class extension:

    @interface MyBaseClass ()
    @property (nonatomic, readwrite, retain) NSObject *someObject;
    @end
    

    You are then free to make that declaration both in MyBaseClass and in MySubclass. This lets MySubclass know about these properties so that its code can talk about them.

    If the repetition bothers you, put the class extension in a .h file of its own and import it into both .m files.

    I will give an example from my own code. Here is MyDownloaderPrivateProperties.h:

    @interface MyDownloader ()
    @property (nonatomic, strong, readwrite) NSURLConnection* connection;
    @property (nonatomic, copy, readwrite) NSURLRequest* request;
    @property (nonatomic, strong, readwrite) NSMutableData* mutableReceivedData;
    @end
    

    There is no corresponding .m file and that’s all that’s in this file; it is, as it were, purely declarative. Now here’s the start of MyDownloader.m:

    #import "MyDownloader.h"
    #import "MyDownloaderPrivateProperties.h"
    @implementation MyDownloader
    @synthesize connection=_connection;
    @synthesize request=_request;
    @synthesize mutableReceivedData=_mutableReceivedData;
    // ...
    

    And here’s the start of its subclass MyImageDownloader.m:

    #import "MyImageDownloader.h"
    #import "MyDownloaderPrivateProperties.h"
    

    Problem solved. Privacy is preserved, as these are the only classes that import MyDownloaderPrivateProperties.h so they are the only classes that know about these properties as far as the compiler is concerned (and that’s all that privacy is in Objective-C). The subclass can access the private properties whose accessors are synthesized by the superclass. I believe that’s what you wanted to accomplish in the first place.

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

Sidebar

Related Questions

I have this user defined function. public partial class UserDefinedFunctions { static int i;
I have a declarative table defined like this: class Transaction(Base): __tablename__ = transactions id
We have a class Car defined like this in a car.rb file class Car
I have a model defined this way class Lga < ActiveRecord::Base validates_uniqueness_of :code validates_presence_of
I have an inline member function defined under class MyClass int MyClass::myInlineFunction(); This function
I have a class called MainGame, which is defined like this in my .h:
I've defined a class with the following property: private ObservableCollection<Job> allJobs; Access is defined
In C++ I have defined a class that has this as a member: static
I have this class header //header for class. #ifndef Container_H #define Container_H #include <iostream>
I have a class that defines its own enum like this: public class Test

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.