问题
I am trying to run the following test from Chapter 16: Testing with RxTest of Raywenderlich RxSwift book:
import XCTest
import RxSwift
import RxTest
@testable import Testing
class TestingViewModel : XCTestCase {
var viewModel: ViewModel!
var scheduler: ConcurrentDispatchQueueScheduler!
override func setUp() {
super.setUp()
viewModel = ViewModel()
scheduler = ConcurrentDispatchQueueScheduler(qos: .default)
}
func testColorNameIsRayWenderlichGreenWhenHexStringIs006636() {
// 1
let colorNameObservable = viewModel.colorName.asObservable().subscribeOn(scheduler)
// 2
viewModel.hexString.value = "#006636"
// 3
XCTAssertEqual("rayWenderlichGreen", try! colorNameObservable.toBlocking().first()!)
}
}
But I get this error on the simulator:
Undefined symbols for architecture x86_64: "type metadata for RxCocoa.DriverSharingStrategy", referenced from: TestingTests.TestingViewModel.testColorNameIsRayWenderlichGreenWhenHexStringIs006636() -> () in TestingViewModel.o "protocol witness table for RxCocoa.DriverSharingStrategy : RxCocoa.SharingStrategyProtocol in RxCocoa", referenced from: TestingTests.TestingViewModel.testColorNameIsRayWenderlichGreenWhenHexStringIs006636() -> () in TestingViewModel.o "RxCocoa.SharedSequence.asObservable() -> RxSwift.Observable", referenced from: TestingTests.TestingViewModel.testColorNameIsRayWenderlichGreenWhenHexStringIs006636() -> () in TestingViewModel.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
And This one on iPhone 6s:
Undefined symbols for architecture arm64: "type metadata for RxCocoa.DriverSharingStrategy", referenced from: TestingTests.TestingViewModel.testColorNameIsRayWenderlichGreenWhenHexStringIs006636() -> () in TestingViewModel.o "protocol witness table for RxCocoa.DriverSharingStrategy : RxCocoa.SharingStrategyProtocol in RxCocoa", referenced from: TestingTests.TestingViewModel.testColorNameIsRayWenderlichGreenWhenHexStringIs006636() -> () in TestingViewModel.o "RxCocoa.SharedSequence.asObservable() -> RxSwift.Observable", referenced from: TestingTests.TestingViewModel.testColorNameIsRayWenderlichGreenWhenHexStringIs006636() -> () in TestingViewModel.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Unfortunately, there is no support for this issue in Raywenderlich's forums.
回答1:
After a lot of searches, As somebody suggests here for another similar issue I found that this error will be solved by importing RxCocoa
.
来源:https://stackoverflow.com/questions/50465639/rxtest-undefined-symbols-for-architecture-x86-64-and-arm64