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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:17:13+00:00 2026-05-22T23:17:13+00:00

Please refer to the following code: Filename: myclass.h @interface myclass:NSObject … @end @interface NSObject(CategoryName)

  • 0

Please refer to the following code:

Filename: myclass.h

@interface myclass:NSObject
...
@end
@interface NSObject(CategoryName)
....
@end

I do not understand how can we declare 2 @interface directives in the same .h file? and like in the implementation file we can only implement one of the above interfaces.eg.

Filename: myclass.m

@implementation myclass
...
@end 

in the above code, i cannot write @implementation Categoryname as the name of the .h file is myclass. How do i implement the methods described in the category.

Also can my main interface extend one class and the category that i am defining in the same .h file extend another class?

How can i declare one class into another class (nested class) in objective c?

thank you in advance.

UPDATE

After reading the responses, i have 2 more questions

  1. if i have 2 @interface in my .h file, can i have 2 @implementation in the .m file.
  2. if i have 2 @interface in my .h file and if i import that .h file in another file, can i access the methods under both the @interface directives?
  3. Can i implement the methods declared in the category in the interface of another class?
  • 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-22T23:17:13+00:00Added an answer on May 22, 2026 at 11:17 pm

    Add it as another declaration in the same file, like this

    @implementation NSObject (categoryname)
    
    ...
    
    @end
    

    It’s all described in the Categories and extensions section of the Developer docs.

    Since you are extending a different class in the same interface – you need to have a separate declaration in the implementation file.

    Edited to answer the additions:

    1. Yes – I just said so.
    2. Yes – Interfaces expose public methods.
    3. Somewhere in your compilation tree, you have to have a file that implements the methods that you declared in your category. Most people define categories in their own files with a particular naming convention.For example uliwitness/uikit. For your example it would be in NSObject+CategoryName.h and NSObject+CategoryName.m. Once you have declared and defined a category on a class it is available to all objects of that class. So since you are adding an extension to NSObject, those methods are available to all classes that inherit from NSObject (which is practically all classes) whether or not you import the header file. But, you get a compiler warning if you don’t import the header, even though the Objective-C runtime will still allow those methods to be called.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi please refer the following HTML code: <div id=content> <p> <font size='2'> <img src=something.jpg
I am not that familiar with PyGTK. Please see the following code. Is it
I have the following test code #include <iostream> template <typename T> struct PS {
I'm making a cropping tool for images and I can't for the life of
SOLVED: added some java to the Page 1 code to read the URL parameters
I'm having an issue where after the 10th page, the next page seems to
I'm getting this message each time I activate my plugin: The plugin generated 80
I'm one of the developers of TryAgain, a Firefox add-on, that displays a custom
I am working on an application in which I need to migrate the whole
I am working on a new PHP project now, this time I want to

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.