I'm playing around with custom actor executors a bit ... as seen in What's new in Swift at WWDC 2023...
The following code errors out:
@available(iOS 17.0, *)
actor TestActor {
private let queue: DispatchSerialQueue
nonisolated var unownedExecutor: UnownedSerialExecutor { queue.asUnownedSerialExecutor() }
...
Value of type 'DispatchSerialQueue' has no member 'asUnownedSerialExecutor'
There is the _DispatchSerialExecutorQueue that actually does provide the asUnownedSerialExecutor() function ... This conflicts a bit with what Doug said during the talk...
"The synchronization of actors via dispatch queues is made possible because dispatch queue conforms to the new SerialExecutor protocol."
https://developer.apple.com/wwdc23/10164?time=2206
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I'm trying to see what I am doing wrong ... So I created this simple app where the stateobject Retainer won't get deallocated when I pop the view off the stack:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
List {
NavigationLink("To Retain Cycle") {
RetainCycleView()
}
}
.navigationTitle("Retain Cycle Demo")
}
.navigationViewStyle(.stack)
}
}
struct RetainCycleView: View {
@StateObject var model = Retainer()
// @State var enteredText: String = ""
var body: some View {
VStack(alignment: .leading, spacing: 4) {
Text("Navigate back to the previous view.")
Text("You will see that 'Retainer' was NOT deallocated.")
Text("(it's deinit function prints deallocing Retainer)")
.font(.callout)
}
.padding()
.searchable(text: $model.enteredText)
// ^---- retain cycle
// .searchable(text: $enteredText)
// ^---- no retain cycle when using the @State var
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
class Retainer: ObservableObject {
@Published var enteredText: String = ""
init() { print("instantiated Retainer") }
deinit { print("deallocing Retainer") }
}
I filed feedback but I am not entirely sure that this isn't me making some mistake ...
Please help me