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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:05:25+00:00 2026-06-08T17:05:25+00:00

I noticed this while using iOS6 beta 3 When I create a new subclass

  • 0

I noticed this while using iOS6 beta 3

When I create a new subclass of a UIViewContoller (no other parent classes generate this behavior that I’ve noticed), the .m file now has an empty category at the top of the file. In the past when learning about categories I noticed that some people would use this same technique to indicate private methods (although not truly private).

Is that what the intent is here? Has there been any change to making things actually private now? I notice the @private directive out there too.

What is your person coding style regarding private vars and methods?

UPDATE: Since XCode is pushing us to use the class extensions, I went ahead and used them for private methods/ivar for this project. I found a drawback though. I saw that I could reuse one of my subclassed UIViewControllers along with all of it’s UIButtons, UILabels, etc…. I had this inheritance:
UIViewController <- FirstViewController <- SecondViewController.

Well, all of the private methods that I put in the class extension of FirstViewController do not pop up in the autocomplete when I code in SecondViewController. A slight annoyance….

  • 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-08T17:05:34+00:00Added an answer on June 8, 2026 at 5:05 pm

    You’re referring to this interface definition:

    @interface MYViewController ()
    @end
    

    This is technically a class extension rather than a category. Categories have a string inside the parentheses. Class extensions are added to the class at compile time, and so can add ivars (usually in the form of properties). Categories are added at runtime and cannot add ivars.

    All that said, your point is correct. This is used to define private methods and properties.

    In the ObjC world, “private” is a “no trespassing” sign, not a razor-wire wall. While there is a @private keyword (that adds compiler enforcement), it only applies to ivars, and generally isn’t necessary. This type of warning-based privacy works very well in ObjC and is quite sufficient.

    Put your private properties in this class extension, and outside callers will get “may not respond to selector” warnings if they try to access them (just like they would get for calling any undefined method). You should never allow warnings to exist in an ObjC project, so this enforces data encapsulation.


    EDIT

    If they’re private, then they shouldn’t pop up in your subclass. What you want is protected. There’s no great scheme for protected methods in ObjC, but a common technique is to put them into a category in a .h file like MYViewController+Protected.h. I find this comes up very seldom in practice, since so much of good ObjC design doesn’t subclass. It uses composition and delegation instead.

    Regarding “Why just view controllers.” First, it’s not just view controllers. It’s just view controllers on iOS (well, VC, TableViewController, and GLKViewController). On Mac, it’s also window controllers and spotlight importers. Look in:

    .../Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates
    .../Library/Xcode/Templates
    

    But why those? Well, those are all controllers, and it’s insanely common for controllers to need private properties. In fact, if you don’t have private properties in a controller, you’re probably making too much public. That’s not as universal of model and view classes. I suspect that played into their decision. It might also have been different people who owned the templates, or that they were updated at different times. Sometimes you see little inconsistencies that smooth out over time.

    You can make your own templates as well. See Creating Custom Xcode 4 File Templates.

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

Sidebar

Related Questions

I noticed this while using Qt, going through the code examples. When they try
Using SQL Server 2005. This is something I've noticed while doing some performance analysis.
So I have noticed this while using a few differnt languages on Windows XP,
While reading this class BitmapFactory I noticed that almost all methods inside are static.
While working on this question , I noticed that GCC (v4.7)'s implementation of std::function
While I am studying the new django docs on class-based views, I notice this
While using jCart I noticed that it did not work on the iPhone. After
While using IntelliJ Idea to code Scala I've noticed it to use to offer
I was using Gridview for a while now and I have noticed that its
While using the paperclip plugin on Rails, I've noticed the max_keys default of 1000.

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.