Publishers.CombineLatest
当将 Publishers.CombineLatest 与运行 Main 以外的线程的 Publishers 一起使用时,并不总是调用.sink 。
这个问题并不是每次都会出现,这就是为什么我创建了连续尝试测试 100 次的单元测试。通常他们会在 4-5 次迭代后失败。
import XCTest
import Combine
class CombineLatestTests: XCTestCase {
override func setUp() {
continueAfterFailure = false
}
func testCombineLatest_receiveOn() {
for x in 0...1000 {
print("---------- RUN \(x)")
let queue1 = DispatchQueue.global(qos: .userInitiated)
let queue2 = DispatchQueue.global(qos: .background)
let subj1 = PassthroughSubject<Int, Never>()
let subj2 = PassthroughSubject<Int, Never>()
let publ1 = subj1.receive(on: queue1).map { value -> Int in
print("-- Observer 1: \(value), Thread: \(Thread.current)")
return value
} …
Run Code Online (Sandbox Code Playgroud) 我正在使用Apple Sprite Kit编写一款小游戏.
我遇到了碰撞问题.有时我不想让两个带有physicsBodys的skSpriteNodes进行交互.
作为一个例子,我有HERO,ENEMYS和SHOTS,我希望SHOTS只与ENEMYS交互.
但是当两个镜头碰撞在一起时,它们会改变它们的位置.
镜头的代码是
shot.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:shot.size];
shot.physicsBody.dynamic = YES;
shot.physicsBody.allowsRotation = FALSE;
shot.physicsBody.categoryBitMask = playerShotCategory;
shot.physicsBody.contactTestBitMask = enemyCategory;
Run Code Online (Sandbox Code Playgroud)
并且敌人的代码是
activeGameObject.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:activeGameObject.size];
activeGameObject.physicsBody.dynamic = YES;
activeGameObject.physicsBody.categoryBitMask = enemyCategory;
activeGameObject.physicsBody.contactTestBitMask = playerCategory | playerShotCategory;
activeGameObject.physicsBody.allowsRotation = FALSE;
Run Code Online (Sandbox Code Playgroud)