I have a created a class that is a subclass of AVPlayer, named MyPlayer.
AVPlayer is defined as having @MainActor isolation. It is my understanding that subclasses inherit the same actor isolation is their superclass. So, in my case MyPlayer should be isolated to the main-thread as well.
I have a separate Swift class (not Obj-C based) named PlayerManager. It has a reference to MyPlayer as a property of the class. It is not actor-isolated.
So, my code looks like this:
class MyPlayer: AVPlayer {
var specialTimeRanges: [CMTimeRange] {
currentItem?.seekableTimeRanges.compactMap { $0.timeRangeValue } ?? []
}
class PlayerManager {
private let myPlayer: MyPlayer
....
private func doSomethingWithTime() {
let x = myPlayer.specialTimeRanges
....
}
}
The problem that I have is that there are no warnings generated inside of doSomethingWithTime, and I don't know why.
I would've assumed that MyPlayer.specialTimeRangeswould be isolated to @MainActor, because it's superclass is. Then inside of PlayerManager, which is not isolated, I'd expect to see at least a warning about calling isolated code from a non-isolated context. But I'm not seeing that.
Next up, I tried making doSomethingWithTime an async func, and I do get the warning.
So, I'm not sure what's going on here. In the synchronous func, no warning. Async func, warning. The class is not actor-isolated.
So, either the compiler is not warning me about a possible actor-isolation issue OR I'm just missing something, and the code is OK. I mean, the "sync" case is acting like the function is going to run on the main-thread, but the func is not annotated as such, and neither is the class itself.
What am I missing?