“Cannot find interface declaration for NSObject”?

2019-01-23 17:01发布

So I've done some research into this issue, but I haven't found anything similar just yet...

So I'm coding a game in Obj-C using Xcode and Sparrow Framework. I've been working on the simulator up until this point, and it's all been going fine. But when I switch to running it on my device, I get all sorts of errors for things that should be standard, e.g. "Cannot find interface declaration for NSObject", "Unknown type name 'NSMutableArray'" etc. I've already got #import in each class, so you would think that it shouldn't happen, right? I get the feeling that it's just a line or two that needs changing somewhere - but I haven't got a clue what or where.

If anyone has any advice, it would be very much appreciated. :)

EDIT: Here's a screenshot of one of the .h files that give errors - it seems to only be in some of the .h files that I've created. http://i.imgur.com/EuQh4.png

7条回答
Animai°情兽
2楼-- · 2019-01-23 17:31

Try this instead for Cocoa or iOS app, make sure to import "Foundation/Foundation.h" in your class where you are inheriting NSObject class.

查看更多
我只想做你的唯一
3楼-- · 2019-01-23 17:38

This can be caused by not including UIKit.

Add this to your header:

#include <UIKit/UIKit.h>

Also make sure to add the UIKit Framework to your project. (Targets/Build Phases/Link Binary With Libraries/ -- Select Add --- Add UIKit.Framework)

查看更多
孤傲高冷的网名
4楼-- · 2019-01-23 17:39

Try deleting the derived data for the project. You can do that through the organiser, under projects. You might have a corrupt precompiled header.

查看更多
甜甜的少女心
5楼-- · 2019-01-23 17:47

I faced a similar error, resolved it when I noticed I had done something remarkably stupid.

In my foo.m file, I had forgotten to #import "foo.h"

The error got fixed when I added the import line.

查看更多
祖国的老花朵
6楼-- · 2019-01-23 17:49

Also make sure you're not including an Objective-C file from a .cpp or .c file.

Example: a PhotoManager.mm might include the header file from the Objective-C pair PhotoObject.h/PhotoObject.mm. Then, if MyAwesomeCppFile.cpp includes PhotoManager.h, suddenly PhotoObject.h doesn't know the basic Objective-C classes and keywords.

A solution would be to use #ifdef __OBJC__ if you can get away with it.

Otherwise designate the .cpp file type as Objective-C++ Source in the file's properties panel (Top right window control => "Identity and type")

查看更多
smile是对你的礼貌
7楼-- · 2019-01-23 17:50

Make sure that you don't use a Class Name that is already taken. I've had the same problem when i named one of my Classes "Signal", which is already part of Foundation.

查看更多
登录 后发表回答