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
我有一个现有的快速项目,我无法让这个工作。我一直在收到错误
So as you can see if I don't try to Module-Scope the 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
Framework: ReferenceTest
- File.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 IS public
所以我的问题是在File.swift中我试图引用在DataManager.framework里面的LocationMessages.swift中定义的类。
@objc(DMLocationMessage)
final public class LocationMessage : ParsedMessage {
2 个解决方案
#1
4
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 type DataManager
where it should read module instead.
您可能在代码中的任何位置都有一个类/结构/枚举DataManager,它隐藏了DataManager模块。该错误表明它无法在DataManager类型中找到LocationManager,而应该在其中读取模块。
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 all our 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也明显表明这些模块是应用程序本身的一部分,而不是某些第三方框架。
#2
8
There is also this bug in swift compiler: SR-631 Extensions in different files do not recognize each other
swift编译器中也存在这个错误:不同文件中的SR-631扩展不能互相识别
The result (success/failure) of the compilation depends on the order of files in Build Phase > Compile Sources setting.
编译的结果(成功/失败)取决于“构建阶段”>“编译源”设置中的文件顺序。
I had exactly the same error message: X is not a member type of Y. Solved it by rearranging compilation sources.
我有完全相同的错误消息:X不是Y的成员类型。通过重新安排编译源解决它。
#1
4
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 type DataManager
where it should read module instead.
您可能在代码中的任何位置都有一个类/结构/枚举DataManager,它隐藏了DataManager模块。该错误表明它无法在DataManager类型中找到LocationManager,而应该在其中读取模块。
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 all our 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也明显表明这些模块是应用程序本身的一部分,而不是某些第三方框架。
#2
8
There is also this bug in swift compiler: SR-631 Extensions in different files do not recognize each other
swift编译器中也存在这个错误:不同文件中的SR-631扩展不能互相识别
The result (success/failure) of the compilation depends on the order of files in Build Phase > Compile Sources setting.
编译的结果(成功/失败)取决于“构建阶段”>“编译源”设置中的文件顺序。
I had exactly the same error message: X is not a member type of Y. Solved it by rearranging compilation sources.
我有完全相同的错误消息:X不是Y的成员类型。通过重新安排编译源解决它。