xcode 未知类型名称“NSError”等

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25828208/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:33:06  来源:igfitidea点击:

Unknown type name 'NSError' and others

iosobjective-cxcode

提问by badweasel

I'm not exactly a noob but I completley feel like one right now.

我不完全是一个菜鸟,但我现在完全感觉像一个。

I took an existing working app of mine. One that works under Xcode 5 and now works under Xcode 6. It compiles fine and runs. I started a new project in Xcode 6 and started to rebuild a new app shell using the structure of my working app. Moving over all of my standard libraries in it that I use in every app. I've done this several times under Xcode 5 with no problems.

我拿了我现有的工作应用程序。一个在 Xcode 5 下工作,现在在 Xcode 6 下工作。它编译得很好并运行。我在 Xcode 6 中开始了一个新项目,并开始使用我的工作应用程序的结构重建一个新的应用程序外壳。移动我在每个应用程序中使用的所有标准库。我已经在 Xcode 5 下多次这样做了,没有任何问题。

But now when I build I'm getting a lot of errors in a specific library (TBXML), but I don't get any of those errors on my other working project even though it has the same library. If I take those files out (so it's not compiling them) there are no errors and the app launches fine.

但是现在当我构建时,我在特定的库 (TBXML) 中遇到了很多错误,但是我在其他工作项目中没有遇到任何这些错误,即使它具有相同的库。如果我将这些文件取出(因此它不会编译它们),则不会出现错误并且应用程序可以正常启动。

I'm not even including the library yet. Same errors if I do or don't. But they are listed under Compile Sources and so they're compiling.

我什至还没有包括图书馆。如果我做或不做,同样的错误。但是它们列在编译源下,因此它们正在编译。

The errors are things like: ....blah..../TBXML/TBXML-Headers/TBXML.h:124:49: Unknown type name 'NSError'

错误是这样的: ....blah ..../TBXML/TBXML-Headers/TBXML.h:124:49: Unknown type name 'NSError'

on the line:

在线上:

typedef void (^TBXMLFailureBlock)(TBXML *tbxml, NSError *error);

....blah..../TBXML/TBXML-Headers/TBXML.h:126:71: Unknown type name 'NSString'

....等等..../TBXML/TBXML-Headers/TBXML.h:126:71: 未知类型名称“NSString”

on the line:

在线上:

typedef void (^TBXMLIterateAttributeBlock)(TBXMLAttribute *attribute, NSString *attributeName, NSString *attributeValue);

....blah..../TBXML/TBXML-Headers/TBXML.h:133:20: Cannot find interface declaration for 'NSObject', superclass of 'TBXML'

....blah..../TBXML/TBXML-Headers/TBXML.h:133:20: 找不到“NSObject”的接口声明,“TBXML”的超类

on the line:

在线上:

@interface TBXML : NSObject {

Items to check off the list:

要检查的项目:

  1. I do have all the proper frameworks including Foundation.
  2. no compiler flags for these files - which matches the old project.
  3. Build for and Target iOS is the same on both projects.
  4. I'm not looking for "don't use TBXML" as it works fine as is in the other project.
  1. 我确实拥有所有合适的框架,包括 Foundation。
  2. 这些文件没有编译器标志 - 与旧项目匹配。
  3. Build for 和 Target iOS 在两个项目上是相同的。
  4. 我不是在寻找“不要使用 TBXML”,因为它在其他项目中工作正常。

I'm assuming that it is some difference in project settings as my old project was created under Xcode 5 and this one under Xcode 6. But I've looked everywhere I know to look.

我假设项目设置存在一些差异,因为我的旧项目是在 Xcode 5 下创建的,而这个是在 Xcode 6 下创建的。但我已经查看了我知道的所有地方。

* UPDATE *

* 更新 *

This seems to fix it: TBXML in an iOS 8 extension fails to build

这似乎解决了它:iOS 8 扩展中的 TBXML 无法构建

I would like to know why though. The question is still out there. Why would one project need the #include and the other one not? The main difference is that one was created under Xcode 5 and the other under Xcode 6. But both projects are now in Xcode 6.

我想知道为什么。这个问题仍然存在。为什么一个项目需要#include 而另一个不需要?主要区别在于,一个是在 Xcode 5 下创建的,另一个是在 Xcode 6 下创建的。 但是这两个项目现在都在 Xcode 6 中。

回答by badweasel

Prefix Headers!!!

前缀头!!!

Thanks Hot Licks - you lead me to the answer. In my old project I had this:

感谢 Hot Licks - 你带我找到答案。在我的旧项目中,我有这个:

Xcode Build Settings

Xcode 构建设置

And in the new project I didn't. The contents of that file are:

而在新项目中我没有。该文件的内容是:

#import <Availability.h>

#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
#endif

So basically every file had Foundation and UIKit included. So on the new project there were times when these were needed and not included. Perhaps apple read this: http://qualitycoding.org/precompiled-headers/

所以基本上每个文件都包含 Foundation 和 UIKit。因此,在新项目中,有时需要但不包括这些。也许苹果读过这个:http: //qualitycoding.org/precompiled-headers/