RxSwift TestScheduler用于两个来源

问题描述 投票:0回答:1

我想为两个不同的源发出两个不同的信号,但是我崩溃了第29行的Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)中的RxSwift/Event.swiftreturn "next(\(value))"

这是我的简化代码:

        let scheduler = TestScheduler(initialClock: 0)

        locationsFactory = TestableLocationsFactory()
        locationsFactory.didReceiveRegion = scheduler.createColdObservable([
        .next(100, regionEvents[0]),
        .next(200, regionEvents[1])
        ]).asObservable()

        locationsFactory.location = scheduler.createColdObservable([
        .next(120, locations[0]),
        .next(220, locations[1])
        ]).asObservable()

        let result = scheduler.createObserver(LocationChange.self)
        let dispatcher = BestAccuracyLocationsDispatcher(persistenceService: persistenceService, apiClient: api, locationManager: locationsFactory)

        subscription = dispatcher.dispatcher.subscribe(result)
        scheduler.start()

        let events = result.events

        XCTAssertEqual(events, [
            .next(120, LocationChange(location: locations[0], trigger: .updateLocations)),
            .next(220, LocationChange(location: locations[1], trigger: .updateLocations)),
        ])

当我删除locationsFactory.didReceiveRegionlocationsFactory.location时,它起作用。

我可以创建两个不同的调度程序的可观察对象吗?

swift rx-swift rxtest
1个回答
0
投票

我使用了区域let region = CLRegion()的模拟物,这是一个抽象类。当我将其更改为:

时,它开始工作

let region = CLCircularRegion(center: CLLocationCoordinate2D(latitude: 5.555, longitude: 6.666), radius: Double(50), identifier: "xxx")

© www.soinside.com 2019 - 2024. All rights reserved.