@objc
public class SomeObject: NSObject {
public override init() {
super.init()
}
public func someMethod() {
print("object invoked")
}
}
@objc
public class ObjCWrapper: NSObject {
@objc
public func sendingMethod(_ val: sending Any) {
// do nothing
}
}
I am creating SomeObject and passing it to ObjCWrapper.sendingMethod in Objective C:
It seems like in case sending in Swift, ARC counter is not updated when object is passed from Objective C. Similar logic in Swift doesn't cause any crash, e.g. Implementing startScenario in Swift doesn't cause any crash:
func startScenario() {
let obj = SomeObject()
let wrapper = ObjCWrapper()
NSLog("SomeObject address: %p", obj)
wrapper.sendingMethod(obj)
Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true) { _ in
NSLog("SomeObject address: %p", obj)
}
}
I realize that this isn't what you were asking about. However, I'm fairly sure there's another issue here.
The non-Sendable obj value is passed as a sending parameter to sendingMethod, but is then captured by a closure (and an @Sendable one, no less). This should be invalid. I think that Timer's preconcurrency status is messing things up here, but I'm not certain.