Cesare
Cesare

Reputation: 9409

Objective-C can't see class declaration

This is for an online course project Objective-C for Swift developers. I created a command-line Objective-C project, and then add a class called House to my project using the dropdown New File > Cocoa Class menu. However, referencing the class in the main file does not work (getting "Use of unresolved identifier House" compile-time error):

main.m file:

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        House *myHouse = [[House alloc] init];
    }
    return 0;
}

House header file:

#import <Foundation/Foundation.h>

@interface House : NSObject

@end

House implementation file:

#import "House.h"

@implementation House

@end

I've deleted the Derived Data folder and restarted the Xcode project with no success. Also, the House.m file in listed under the Compile Resources the project settings. This must be so simple. Why can't Xcode see the class?

Upvotes: 0

Views: 73

Answers (1)

Gereon
Gereon

Reputation: 17844

You need to #import "House.h" in your main.m

Upvotes: 3

Related Questions