xcode X 不是 Y 的成员类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34159442/
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
X is not a member type of Y
提问by Jeef
I'm having staring issues with Module name spacing in a swift project.
我在 swift 项目中遇到了模块名称间距的问题。
I've tried this in a new project and everything works fine:
我在一个新项目中尝试过这个,一切正常:
I have 2 modules with which contain the same class name and i'm able to reference the class from Module.Class
no problem.
我有 2 个包含相同类名的模块,我可以Module.Class
毫无问题地引用该类。
I have an existing swift project and I'm unable to get this working. I keep getting the error
我有一个现有的 swift 项目,但我无法让它工作。我不断收到错误
So as you can see if I don't try to Module-Scopethe class everything works fine.
因此,如您所见,如果我不尝试使用Module-Scope类,则一切正常。
(And yes i've tried with and with out the .Type
addition).
(是的,我尝试过添加和不.Type
添加添加)。
So I'm assuming there is something off in my compiler setting. The only other thing I can think of is that my LocationMessage class is defined not in the main DataManager "class" file but rather in a different file.
所以我假设我的编译器设置有问题。我唯一能想到的另一件事是我的 LocationMessage 类不是在主 DataManager“类”文件中定义的,而是在不同的文件中定义的。
But I really can't make heads or tails of whats going on. Any suggestions?
但我真的无法理解正在发生的事情。有什么建议?
Project Structure
项目结构
Framework: DataManager
框架:数据管理器
- DataManager.swift
- LocationMessages.swift
- 数据管理器.swift
- LocationMessages.swift
Framework: ReferenceTest
框架:ReferenceTest
- File.swift
- 文件.swift
So my issue is that in File.swift
I'm trying to reference a class defined in LocationMessages.swift
inside the DataManager.framework
The class ISpublic
所以我的问题是,File.swift
我想引用定义的类LocationMessages.swift
里面DataManager.framework
的类IS公众
@objc(DMLocationMessage)
final public class LocationMessage : ParsedMessage {
采纳答案by fluidsonic
You likely have a class/struct/enum DataManager
anywhere in your code which hides the DataManager
module. The error states that it cannot find LocationManager
in typeDataManager
where it should read moduleinstead.
您class/struct/enum DataManager
的代码中可能有一个隐藏DataManager
模块的地方。该错误指出它无法LocationManager
在类型DataManager
中找到它应该读取模块的位置。
Your app modules should be designed in a way so that you never need to explicitly use the module's name except for the import
statement. So just use LocationMessage.Type
directly without stating the module.
您的应用程序模块的设计方式应该使您永远不需要显式使用模块的名称,除了import
语句。所以直接使用LocationMessage.Type
,不用说明模块。
This is one reason allour app's modules are prefixed with an X
, e.g. XDataManager
. This avoids conflicts with Apple's modules, external modules (like from CocoaPods) and with types (like in your case).
The X
also makes it obvious that these modules are part of the app itself and not some third-party frameworks.
这是我们所有应用程序模块都以 为前缀的原因之一X
,例如XDataManager
。这避免了与 Apple 的模块、外部模块(如 CocoaPods)和类型(如您的情况)发生冲突。
这X
也表明这些模块是应用程序本身的一部分,而不是某些第三方框架。
回答by Anton
There is also this bug in swift compiler: SR-631 Extensions in different files do not recognize each other
swift编译器中也有这个bug:不同文件中的SR-631 Extensions不相互识别
The result (success/failure) of the compilation depends on the order of files in Build Phase > Compile Sourcessetting.
编译的结果(成功/失败)取决于Build Phase > Compile Sources设置中的文件顺序。
I had exactly the same error message: X is not a member type of Y. Solved it by rearranging compilation sources.
我有完全相同的错误消息:X 不是 Y 的成员类型。通过重新排列编译源解决了它。
回答by Derryl Thomas
In case anyone is here while trying to build and use an xcframework, apparently, the issue is caused when you have a class in the framework which has the same name as the module/framework.
如果有人在尝试构建和使用 xcframework 时在这里,显然,当您在框架中有一个与模块/框架同名的类时会导致问题。
This is a known issue and needs a workaround as mentioned here.
这是一个已知问题,需要此处提到的解决方法。
P.S. - I know this doesn't answer this question per se. Just leaving it here for anyone else who might land here because of the question title.
PS - 我知道这本身并不能回答这个问题。只是把它留在这里给任何可能因为问题标题而降落在这里的人。