Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 添加类时显示错误消息 我有一个名为PrimeNoMe的类,我最近写过,它在基础工具和MAC应用程序中运行得很好。但是,尝试将其用于iPhone应用程序失败。我将.m和.h文件添加到我的项目中,并将.h文件导入到我的ViewController.h中,如下所示: #import "PrimeNumber.h"_Objective C_Xcode_Class - Fatal编程技术网

Objective c 添加类时显示错误消息 我有一个名为PrimeNoMe的类,我最近写过,它在基础工具和MAC应用程序中运行得很好。但是,尝试将其用于iPhone应用程序失败。我将.m和.h文件添加到我的项目中,并将.h文件导入到我的ViewController.h中,如下所示: #import "PrimeNumber.h"

Objective c 添加类时显示错误消息 我有一个名为PrimeNoMe的类,我最近写过,它在基础工具和MAC应用程序中运行得很好。但是,尝试将其用于iPhone应用程序失败。我将.m和.h文件添加到我的项目中,并将.h文件导入到我的ViewController.h中,如下所示: #import "PrimeNumber.h",objective-c,xcode,class,Objective C,Xcode,Class,在尝试使用PrimeNumber类中声明的方法并运行应用程序后,Xcode向我显示了两个错误: Undefined symbols for architecture i386: "_OBJC_CLASS_$_PrimeNumber", referenced from: objc-class-ref in ViewController.o ld: symbol(s) not found for architecture i386 clang: error: linker command faile

在尝试使用PrimeNumber类中声明的方法并运行应用程序后,Xcode向我显示了两个错误:

Undefined symbols for architecture i386:
"_OBJC_CLASS_$_PrimeNumber", referenced from:
objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
PrimeNumber.h和PrimeNumber.m文件在项目导航器中不是红色的。产品>清洁也不起作用。另外,因为我的类不是在框架中声明的,所以我认为这样的事情不会成为问题

谁能告诉我我做错了什么?谢谢

编辑:将类名更改为PrimeNumbers,然后创建一个名为PrimeNumbers的新Objective-C类,并将PrimeNumbers类的.h和.m文件的完整内容复制粘贴到PrimeNumbers类的.h和.m文件中。奇怪,但它奏效了。:)

您还必须将其添加到“编译源代码”构建阶段。
Project->Targets->[Your Target]->构建阶段->编译源代码(只需将
PrimeNumber.m
拖动到其中)

是否执行
PrimeNumber.h
也导入
ViewController.h
?重命名和复制粘贴工作正常,因为当您通过Xcode添加新类时,它会自动将其添加到编译源代码构建阶段。当您将源文件拖放到项目中时,它不会这样做。