将“评论”重新定义为swift中的不同类型的符号

时间:2021-12-31 20:14:56

I have a class Comment declared as such:

我有一个类注释声明如下:

public class Comment: NSManagedObject {
    vars and methods...
}

When I try to compile my project, I get an error that reads: "Redefinition of 'Comment' as different kind of symbol in swift." It highlights this line in the generated .h file: @interface Comment : NSManagedObject, and it tells me that the original declaration of Comment is in AIFF.h (something part of Foundation) and the line of the declaration is: typedef struct Comment Comment;.

当我尝试编译我的项目时,我得到一个错误,上面写着:“将'Comment'重新定义为swift中不同类型的符号。”它在生成的.h文件中突出显示这一行:@interface注释:NSManagedObject,它告诉我注释的原始声明是在AIFF.h(Foundation的一部分)中,声明的行是:typedef struct Comment Comment ;。

I've only recently gotten this problem, and I've built the project with a Comment object successfully before. Why would an error like this happen in Swift?

我最近才遇到这个问题,之前我成功地用一个Comment对象构建了这个项目。为什么在Swift中会发生这样的错误?

Edit

If I remove the NSManagedObject superclass it compiles...

如果我删除NSManagedObject超类,它编译...

1 个解决方案

#1


1  

It may be a case that your class Comment is defined somewhere else in Foundation framework. What you need to do is importing only specific classes that you need inside your file. First remove all import statements in the source file and then import NSManagedObject like this:

可能是您的类Comment在Foundation框架中的其他位置定义的情况。您需要做的是仅导入文件中需要的特定类。首先删除源文件中的所有import语句,然后像这样导入NSManagedObject:

import class CoreData.NSManagedObject

Then you will gain access to the NSManagedObject class you need for your Comment subclass. If you need any classes or structs from Foundation framework (for example NSError) you should import them like this:

然后,您将获得对Comment子类所需的NSManagedObject类的访问权限。如果你需要来自Foundation框架的任何类或结构(例如NSError),你应该像这样导入它们:

import class Foundation.NSError

This will eliminate compiler errors about redefinition of class Comment.

这将消除有关重新定义类Comment的编译器错误。

Also make sure to clean the project and clean build folder by using Command + Shift + K and Command + Shift + alt + K

还要确保使用Command + Shift + K和Command + Shift + alt + K清理项目并清理构建文件夹

#1


1  

It may be a case that your class Comment is defined somewhere else in Foundation framework. What you need to do is importing only specific classes that you need inside your file. First remove all import statements in the source file and then import NSManagedObject like this:

可能是您的类Comment在Foundation框架中的其他位置定义的情况。您需要做的是仅导入文件中需要的特定类。首先删除源文件中的所有import语句,然后像这样导入NSManagedObject:

import class CoreData.NSManagedObject

Then you will gain access to the NSManagedObject class you need for your Comment subclass. If you need any classes or structs from Foundation framework (for example NSError) you should import them like this:

然后,您将获得对Comment子类所需的NSManagedObject类的访问权限。如果你需要来自Foundation框架的任何类或结构(例如NSError),你应该像这样导入它们:

import class Foundation.NSError

This will eliminate compiler errors about redefinition of class Comment.

这将消除有关重新定义类Comment的编译器错误。

Also make sure to clean the project and clean build folder by using Command + Shift + K and Command + Shift + alt + K

还要确保使用Command + Shift + K和Command + Shift + alt + K清理项目并清理构建文件夹