Closed zachwaugh closed 2 weeks ago
Hi @zachwaugh, I'm not able to reproduce this with the following test
import AppKit
import XCTest
class MacTests: XCTestCase {
@MainActor
func testTokenStorage() {
class Controller: NSViewController {
override init(nibName nibNameOrNil: NSNib.Name?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
observe {}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
let controller = Controller(nibName: nil, bundle: nil)
_ = controller
}
}
Can you provide a repro for us to look into?
Interesting! I can't reproduce with that either, but noticed the one difference in my app is multiple observe
calls and that seems to be the thing. This will reproduce it:
import AppKit
import XCTest
class MacTests: XCTestCase {
@MainActor
func testTokenStorage() {
class Controller: NSViewController {
override init(nibName nibNameOrNil: NSNib.Name?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
observe {}
// 🚨 Crashes on second observe
observe {}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
let controller = Controller(nibName: nil, bundle: nil)
_ = controller
}
}
Ah, interesting! That does reproduce for me. Thanks for that, will look into it more.
This will be fixed once we merge and release https://github.com/pointfreeco/swift-navigation/pull/212/. If you want an immediate fix you could copy-paste the observe
helper into your code and change the Set<ObserveToken>
to an [Any]
, then it will work.
This is fixed in swift-navigation@2.1.0
.
Description
After the update to 1.13.1,
observe
is crashing in my macOS app. The actual error is:I'm assuming because
ObserveToken
in SwiftNavigation does not conform toNSObject
- https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Observe.swift#L162. Where as the previous implementation ofobserve
in TCA did use a class derived fromNSObject
https://github.com/pointfreeco/swift-composable-architecture/blob/1.12.1/Sources/ComposableArchitecture/UIKit/NSObject%2BObservation.swift#L200Checklist
main
branch of this package.Expected behavior
No response
Actual behavior
No response
Steps to reproduce
No response
The Composable Architecture version information
1.13.1
Destination operating system
macOS 14.5
Xcode version information
Xcode 15.4
Swift Compiler version information
No response