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

  • Home
  • SEARCH
  • 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 8592917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:52:00+00:00 2026-06-11T23:52:00+00:00

According to some official talk, a class in Objective-C should only expose public methods

  • 0

According to some official talk, a class in Objective-C should only expose public methods and properties in its header:

@interface MyClass : NSObject

@property (nonatomic, strong) MyPublicObject *publicObject;

- (void)publicMethod;

@end

and private methods/properties should be kept in class extension in .m file:

@interface MyClass()

@property (nonatomic, strong) MyPrivateObject *privateObject;

- (void) privateMethod;

@end

and I don’t think there is a protected type for things that are private but accessible from subclasses. I wonder, is there anyway to achieve this, apart from declaring private properties/methods publicly?

  • 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-11T23:52:01+00:00Added an answer on June 11, 2026 at 11:52 pm

    One way to solve this is to re-declare the property in your subclass’s class extension, and then add an @dynamic statement so that the compiler won’t create an overriding implementation of that property. So something like:

    @interface SuperClass ()
    
    @property (nonatomic, strong) id someProperty;
    
    @end
    
    ....
    
    
    @interface SubClass ()
    
    @property (nonatomic, strong) id someProperty;
    
    @end
    
    @implementation SubClass
    
    @dynamic someProperty;
    
    @end
    

    This obviously isn’t ideal because it duplicates a privately visible declaration. But it is quite convenient and helpful in some situations so I’d say evaluate on a case-by-case basis the dangers involved in this duplication vs. exposing the property in the public interface.

    An alternative – that is used by Apple in UIGestureRecognizer – is to declare the property in a separate category header file explicitly named as “private” or “protected” e.g. “SomeClass+Protected.h”. That way, other programmers will know they ought not import the file. But, if you don’t control the code you’re inheriting from, that’s not an option.

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

Sidebar

Related Questions

I am thinking about some details regarding stringByReplacingOccurrencesOfString:withString: in NSString class According to document.
If i have a form which action should differ according to some session variable
I have a DateTime class and wish to display it according to some format...
According to some SEO experts and theories like Progressive Enhancement (PE), page content should
I am trying to make ListBox which updates its content according to some changing
according to some tutorials i read a while back, the const declaration makes a
I'm trying to set default scope according to some criteria determined by ana ActionController
How to show or hide a field for some records according to condition in
According to Learn you some Erlang : Pretty much any function you can think
According to MSDN BOL (Books Online) description on SOME | ANY (Transact-SQL) , SOME

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.