【发布时间】:2020-04-26 19:59:26
【问题描述】:
我在 Swift 中的 UITest 项目中遇到了一个非常奇怪的错误。
Undefined symbols for architecture x86_64:
"protocol conformance descriptor for IntroductionToMocking.User : Swift.Decodable in IntroductionToMocking", referenced from:
lazy protocol witness table accessor for type IntroductionToMocking.User and conformance IntroductionToMocking.User : Swift.Decodable in IntroductionToMocking in MockHTTPClient.o
"protocol descriptor for IntroductionToMocking.HTTPClientProtocol", referenced from:
protocol conformance descriptor for IntroductionToMockingUITests.MockHTTPClient : IntroductionToMocking.HTTPClientProtocol in IntroductionToMockingUITests in MockHTTPClient.o
"type metadata for IntroductionToMocking.User", referenced from:
IntroductionToMockingUITests.MockHTTPClient.authenticate(username: Swift.String, password: Swift.String, completion: (IntroductionToMocking.User?) -> ()) -> () in MockHTTPClient.o
lazy protocol witness table accessor for type IntroductionToMocking.User and conformance IntroductionToMocking.User : Swift.Decodable in IntroductionToMocking in MockHTTPClient.o
在我的 UITest 项目中,我创建了使用 HTTPClientProtocol 的 MockHTTPClient,如下所示:
import Foundation
@testable import IntroductionToMocking
class MockHTTPClient: HTTPClientProtocol {
func authenticate(username: String, password: String, completion: @escaping (User?) -> Void) {
guard let url = Bundle(for: MockHTTPClient.self).url(forResource: "auth-success-response", withExtension: "json"),
let data = try? Data(contentsOf: url) else {
return completion(nil)
}
let user = try? JSONDecoder().decode(User.self, from: data)
completion(user)
}
}
协议在主项目中定义如下:
import Foundation
protocol HTTPClientProtocol {
func authenticate(username: String, password: String, completion: @escaping (User?) -> Void )
}
我无法弄清楚发生了什么以及为什么会出现错误。有任何想法吗?
【问题讨论】:
-
@TylerTheCompiler 是的,我已经导入了。
-
我在 Xcode 12 中看到了相同的 3 个错误,因为项目在 Xcode 11 中编译良好!您解决了这个问题吗?
-
@AshleyMills 你解决了这个问题吗?
-
可能您的模型之一符合 Identifiable 并且您正在运行 iOS