X 不是 Y 的成员类型 [英] X is not a member type of Y
问题描述
我在 swift 项目中遇到了模块名称间距问题.
I'm having staring issues with Module name spacing in a swift project.
我在一个新项目中尝试过这个,一切正常:
I've tried this in a new project and everything works fine:
我有 2 个包含相同类名的模块,我可以从 Module.Class
引用该类,没问题.
I have 2 modules with which contain the same class name and i'm able to reference the class from Module.Class
no problem.
我有一个现有的 swift 项目,但我无法让它工作.我不断收到错误
I have an existing swift project and I'm unable to get this working. I keep getting the error
所以你可以看到如果我不尝试 Module-Scope 类,一切正常.
So as you can see if I don't try to Module-Scope the class everything works fine.
(是的,我尝试过使用和不使用 .Type
添加).
(And yes i've tried with and with out the .Type
addition).
所以我假设我的编译器设置有问题.我能想到的唯一另一件事是我的 LocationMessage 类不是在主 DataManager类"中定义的.文件,而是在不同的文件中.
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.
但我真的无法理解正在发生的事情.有什么建议吗?
But I really can't make heads or tails of whats going on. Any suggestions?
框架:DataManager
- DataManager.swift
- LocationMessages.swift
框架:ReferenceTest
- File.swift
所以我的问题是在 File.swift
中,我试图在 DataManager.framework
中引用在 LocationMessages.swift
中定义的类> 类 IS 公开
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
@objc(DMLocationMessage)
final public class LocationMessage : ParsedMessage {
推荐答案
您可能在代码中的任何位置都有一个 class/struct/enum DataManager
来隐藏 DataManager
模块.该错误指出它在 type DataManager
中找不到 LocationManager
应该读取 module 的位置.
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.
您的应用模块的设计方式应使您无需显式使用模块名称,import
语句除外.所以直接使用LocationMessage.Type
,不用说明模块.
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.
这是所有我们应用的模块都以X
为前缀的原因之一,例如XDataManager
.这避免了与 Apple 的模块、外部模块(如 CocoaPods)和类型(如您的情况)发生冲突.X
还清楚地表明这些模块是应用程序本身的一部分,而不是某些第三方框架.
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 不是 Y 的成员类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!