-1

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
Shaun Wilson
  • 8,727
  • 3
  • 50
  • 48
Aya Aboud
  • 371
  • 2
  • 4
  • 16

2 Answers2

4
#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....:)

Mohd Prophet
  • 1,511
  • 10
  • 17
2

The difference is very simple.

When you use:

#import <Foundation/NSObject.h>

It'll import only the NSObject header file of Foundation framework.

#import <Foundation/Foundation.h>

All framework have a master header file, which includes all public headers of that particular framework. In common this master header file naming convention is like FrameworkName.h , hence for Foundation framework it'll be Foundation.h and it imports all other public header files of Foundation framework. So if you include that, you don't need to import any other class headers from that framework.

Midhun MP
  • 103,496
  • 31
  • 153
  • 200