Search code examples
iosobjective-cxcodensobjectfoundation

When subclassing NSObject, what difference does it make to import "Foundation.h" or "NSObject.h"?


Here we see the same subclass of NSObject each using a different #import statement. What difference, if any, does this make for my subclass? What difference, if any, does this make for my final compiled program?

#import <Foundation/NSObject.h>
    @interface Card : NSObject

#import <Foundation/Foundation.h>
    @interface Card : NSObject

Solution

  • #import <Foundation/NSObject.h>
        @interface Card : NSObject
    

    In this code ,you are only importing the NSObject class of Foundation framework,So you can't inherit the other classes of Foundation framework.

    While

    #import <Foundation/Foundation.h>
      @interface Card : NSObject
    

    This code allow you to inherit any of the class provided by the Framework like NSProxy,NSRange etc.,as you are importing whole framework.

    Hope it Helps....:)