问题描述
在 Swift
项目中工作时,我有两个模块,比如
While working in Swift
project, I have two modules, let's say
-
基本
-
功能
Base
有一个 SHService
类,从中我可以从其中调用 Feature
模块(类是 SHCommon
).功能模块的构建没有错误,但是 Base
在链接阶段提出了错误.
Base
has a SHService
class from where I am calling a function of Feature
module (of class SHCommon
). Feature module is building without error but Base
raises error in linking phase.
import Foundation
import Feature
class SHService {
public func printMe(printString: String){
SHCommon().printMe(printString: printString)
}
}
Feature.SHCommon
import Foundation
public class SHCommon {
public init(){}
public func printMe(printString: String) {
print(printString)
}
}
链接错误:
知道为什么会这样吗?
推荐答案
查看您的屏幕快照,我试图复制此设置并遇到相同的问题(我不得不说错误消息有点含糊).因此,问题在于您在工作空间中有两个iOS应用程序项目.而且,尽管iOS应用 是一个快速模块,但无法将一个iOS应用导入另一个应用中.但是,您可以做的是将您的 Features
功能转换为框架,然后将该框架导入到 Base
应用程序中.或将 SHCommon
类提取到同时导入 Feature
和 Base
的框架中.
Looking at your screenshot I tried to replicate this setup and got the same problem (I have to say that error message is a bit cryptic). So the problem is that you have two iOS app projects inside workspace. And while iOS app is a swift module, it is impossible to import one iOS app inside another one. What you can do, though, is to convert your Feature
into framework, and then import that framework into Base
app. Or extract SHCommon
class into framework that both Feature
and Base
will import.
More about frameworks: https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html
这篇关于快速链接错误:为Module.Class输入元数据访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!