Swift 链接错误:Module.Class 的类型元数据访问器

Saz*_*han 9 xcode compiler-errors build ios swift

Swift项目中工作时,我有两个模块,比方说

  1. Base
  2. Feature

Base有一个SHService类,我从那里调用Feature模块的函数(类SHCommon)。功能模块正在无错误地构建,但Base在链接阶段引发错误。

工作区快照:

基础服务

import Foundation
import Feature

class SHService {

    public func printMe(printString: String){
        SHCommon().printMe(printString: printString)
    }
}
Run Code Online (Sandbox Code Playgroud)

Feature.SHCommon

import Foundation

public class SHCommon {

    public init(){}
    public func printMe(printString: String) {
        print(printString)
    }
}
Run Code Online (Sandbox Code Playgroud)

链接错误:

知道为什么会这样吗?

小智 5

查看您的屏幕截图,我尝试复制此设置并遇到了同样的问题(我不得不说错误消息有点神秘)。所以问题是您在工作区中有两个 iOS 应用程序项目。虽然 iOS 应用程序一个 swift 模块,但不可能将一个 iOS 应用程序导入到另一个应用程序中。但是,您可以做的是将您的Feature框架转换为框架,然后将该框架导入Base应用程序。或者将SHCommon类提取到框架中,Feature并且Base将导入。

有关框架的更多信息:https : //developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html


小智 5

很长一段时间后我遇到了同样的错误,我找到了解决方案,我必须将未链接的框架(库)添加到任何target您重要的位置General->Frameworks and Libraries


yoA*_*ex5 5

Swift 链接错误:类型元数据访问器

error: type metadata accessor for Module.Class
Run Code Online (Sandbox Code Playgroud)

我在 Xcode 测试目标中遇到此错误。解决方案是:

Test target -> General -> select <app> in Host Application -> Allow testing Host Application APIs
Run Code Online (Sandbox Code Playgroud)