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

The Archive Base Latest Questions

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

This is what I have in my implementation file for one of my classes…

  • 0

This is what I have in my implementation file for one of my classes…

Code Setup #1

@interface MyViewController (PrivateMethods)
- (NSString *)myPrivateMethod;
@end

@implementation MyViewController
- (void)viewDidLoad
{
    NSString *myString = [self myPrivateMethod];
    NSLog(@"%@", myString);
}

- (NSString *)myPrivateMethod
{
    return @"someString";
}
@end

With this code, everything works and it logs “someString”.

But shouldn’t my code look differently somehow? I actually am using that category by accident (I had copy/pasted something and didn’t notice “PrivateMethods” was there; I meant to be using a class extension).

Shouldn’t my code actually look like one of the following:

Code Setup #2

@interface MyViewController ()
- (NSString *)myPrivateMethod;
@end

@implementation MyViewController
....

Or:

Code Setup #3

@interface MyViewController (PrivateMethods)
- (NSString *)myPrivateMethod;
@end

@implementation MyViewController (PrivateMethods)
....

What are the nuances behind what is happening in this situation? How is Code Setup #1 different from Code Setup #2?

Edit: Question about Setup #3

What does setting it up like this accomplish? Would this even “work”?

@interface MyViewController (PrivateMethods)
- (NSString *)myPrivateMethod;
@end

@implementation MyViewController
- (void)viewDidLoad
{
    NSString *myString = [self myPrivateMethod];
    NSLog(@"%@", myString);
}
@end

@implementation MyViewController (PrivateMethods)
- (NSString *)myPrivateMethod
{
    return @"someString";
}
@end
  • 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-11T14:52:02+00:00Added an answer on June 11, 2026 at 2:52 pm

    the selectors just get pushed into the same flat namespace at runtime. the compiler adds no additional code to distinguish that the selector is a method defined in a category (when messaging) –it’s all flat.

    the categories’ symbols are exported differently, but that does not really matter to the runtime once loaded.

    you should generally use Setup #3: if a method is declared in a category, it should be defined in the category’s @implementation. the compiler will save you occasionally and it is a purer structure. (of course, not every method belongs in a category). Similarly, the declarations in the @interface should be defined in the corresponding @implementation, and definitions of declarations in the class continuation (@interface MONClass ()) should also appear in the primary @implementation:

    @implementation MONClass
    // add your @interface MONClass definitions here
    // also add your @interface MONClass () definitions here
    @end
    

    Updated Question

    Yes, that would work fine. All you should need to do is #import the header which contains @interface MyViewController (PrivateMethods). I actually do this in some classes to categorize/organize by topic.

    Typically, “Private Methods” are declared in the class continuation, but it is not necessary to do so (ivars/properties OTOH…).

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

Sidebar

Related Questions

Say I have this code: #import <UIKit/UIKit.h> @interface MyView : UIView @end @implementation MyView
I have an implementation of lazyDataModel following this tutorial http://uaihebert.com/?p=1120 My code its a
I have this pimpl design where the implementation classes are polymorphic but the interfaces
In relation to this question ( Efficient hashCode() implementation ) I have one more
I have an Objective-C++ file, and I have two classes: one Objective-C, one C++:
I have this implementation with fusion table layers where I try to use the
In my implementation I have this: /// <inheritdoc cref=IInterface{T} this[,]/> public T this[long row,
I have this quick sort implementation to sort the characters. int main(){ char val[]
I have this following codes: @implementation MyImageView @synthesize image; //image is a UIImage -
I searched for an implementation of std::map runtime ordering and have found this solution:

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.