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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:31:41+00:00 2026-05-28T19:31:41+00:00

In Objective-C what is the difference between defining something (say a property or a

  • 0

In Objective-C what is the difference between defining something (say a property or a method) in the header file as opposed to the .m file? I’ve heard that it has something to do with making it public or private, but I’m not sure of the details. If this is the case, is this the same as public and private methods in Java?

I’m proficient at Java so any way that you can relate Objective-C to it would be helpful.

Thanks

EDIT: To clarify, suppose I have a class (if that’s the proper term) called “CalculatorBrain”, what is the difference between the following (pay attention to NSMutableArray *operandStack:

In the .m file:

 @interface CalculatorBrain()
 @property (nonatomic, strong) NSMutableArray *operandStack;
 @end

versus, in the .h file:

 @interface CalculatorBrain : NSObject
 @property (nonatomic, strong) NSMutableArray *operandStack;
 @end

What difference does it make where I define NSMutableArray *?

  • 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-28T19:31:42+00:00Added an answer on May 28, 2026 at 7:31 pm

    Alright, following your clarification, I’ll try to explain what’s going on there.

    Let’s say you have this in your header (.h) file:

    @interface Foobar {
    }
    @property (readonly) int numberOfPies;
    @end
    

    This define’s a class‘s public interface. While I’ve said “public” there, I want to make it perfectly clear that Objective-C does not have the same concept of visibility that Java or C++ have (it employs it for instance variables, but that’s the farthest it goes that I’m aware of). I’ve also bolded “class” because there’s an important distinction coming up. The other thing I want to point out is that the class publicly declares the numberOfPies to be readonly, since that’s also going to be important.

    Now, let’s look at the implementation (.m) file for this class:

    @interface Foobar ()
    - (void) doSomething;
    @property (readwrite) numberOfPies;
    @end
    
    @implementation Foobar
    @synthesize numberOfPies;
    
    - (void) doSomething {
      NSLog(@"Doing something");
    }
    
    @end
    

    Look at @interface Foobar () — this begins a class extension. It is not a class declaration. These are also sometimes called private categories, anonymous categories, or class continuations (according to zneak in a comment below), but the important thing to know is that they’re basically a kind of category (I’ve linked to Apple’s documentation on categories). These essentially define additional methods and properties and can be applied to any class whatsoever. They’re used here is to provide what amounts to a private interface for the class (hence “private category”).

    Moving on, now we’ll compare the numberOfPies property between the class and the category. If you didn’t notice the difference yet, here it is: the class exposes it as readonly, the category expands this and makes it readwrite inside the implementation. When synthesizing the property, Obj-C will include both the getter and setter if this happens. The important thing here is that, aside from whether your property is readonly or readwrite, your property cannot change. It can’t have the assign attribute in the class and copy in the category. This basically lets you define a convenient private setter for properties as well.

    One important thing to note here is that absolutely nothing in that category is truly private. Nothing can stop you from sending the doSomething message to a Foobar object, though the compiler will give you a warning outside of the class’s implementation file.

    Following that, you have your standard implementation. This includes implementations for the methods in your anonymous category.

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

Sidebar

Related Questions

Is there a difference between an instance variable and a property in Objective-c? I'm
In Objective-C, what is the difference between the init method (i.e. the designated initializer
What the difference between a method, a selector and a message in Objective-C?
In Objective C (if that matters) is there a difference between these two statements?
What is the difference between weak and strong property setter attributes in Objective-C? @property(retain,
Can some one explain to me the difference between categories and inheritance in Objective
In Objective-C, what's the difference between declaring a variable id versus declaring it NSObject
Could someone please explain the Objective-C difference between myString and anotherString in the following
What's the difference between formal and informal protocols in Objective-C?
What is the difference between class and instance methods in Objective-C and when should

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.