Not working for me neighter, SwiftData do not cascade delete relationships.
Post
Replies
Boosts
Views
Activity
You can temporary fix this problem via:
Duplicate the WatchOS sheme and name it Preview-......
In Edit Scheme > Build Remove the iOS companion app from the list.
Then switch to Preview- scheme when you want to preview the watchOS app Swift views.
You can see the effect in following code.
There are two viewModels, one using ObservableObject and second using @Observable observation framework.
The tabView content views owns the viewModel, however when the parent TabView is redrawed, the ownership of @Observation is teared down and new object is recreated on every redraw of TabView
@StateObject with ObservableObject maintains its view ownership and the object is not deallocated or recreated as would be expected.
@State with @Observable do not follow the ownership, and new object is created every time the parent is redrawed.
Following is the code:
import Observation
import SwiftUI
/// ObservableObject, via @StateObject.
class ViewModelObservable: ObservableObject {
@Published public var title: String
deinit {
print("deinit ViewModelObservable")
}
init(title: String) {
self.title = title
print("init ViewModelObservable")
}
}
/// New Observation framework object.
@Observable
class ViewModelObseration {
public var title: String
deinit {
print("deinit ViewModelObseration")
}
init(title: String) {
self.title = title
print("init ViewModelObseration")
}
}
struct SecondTabContentView: View {
/// View Owns object (Observation Framework)
@State var viewModelObservation: ViewModelObseration
/// View Owns object (Observable Object)
@StateObject var viewModelObservable: ViewModelObservable
init() {
_viewModelObservable = StateObject(wrappedValue: ViewModelObservable(title: "SecondTabContentView Observable"))
_viewModelObservation = State(wrappedValue: ViewModelObseration(title: "SecondTabContentView Observation"))
}
var body: some View {
VStack {
Text(viewModelObservable.title)
Text(viewModelObservation.title)
}
}
}
struct FirstTabContentView: View {
/// View Owns object (Observation Framework)
@State var viewModelObservation: ViewModelObseration
/// View Owns object (Observable Object)
@StateObject var viewModelObservable: ViewModelObservable
init() {
_viewModelObservable = StateObject(wrappedValue: ViewModelObservable(title: "FirstTabContentView Observable"))
_viewModelObservation = State(wrappedValue: ViewModelObseration(title: "FirstTabContentView Observation"))
}
var body: some View {
VStack {
Text(viewModelObservable.title)
Text(viewModelObservation.title)
}
}
}
struct ContentView: View {
@State var tabSelection: Int = 1
@State var redrawTrigger: Bool = false
var body: some View {
TabView(selection: $tabSelection) {
FirstTabContentView()
.tag(0)
.tabItem { Label("First \(redrawTrigger ? "true" : "false") ", systemImage: "pen") }
SecondTabContentView()
.tag(1)
.tabItem { Label("Second \(redrawTrigger ? "true" : "false")", systemImage: "pen") }
}
.task {
try? await Task.sleep(for: .seconds(3))
self.redrawTrigger = true
try? await Task.sleep(for: .seconds(3))
self.redrawTrigger = false
}
}
}
#Preview {
ContentView()
}
The same issue happening for me on Monterrey, please fix that.
My app is authorized for Location Push, get extension entitlement, and upon calling startMonitoringLocationPushes I am getting a valid token.
I am also sending the location Push via token APNS authorization, however the Location Push Extension never wakes up. Any ideas on why the extension is not passing by didReceiveLocationPushPayload(_ payload: [String : Any], completion: @escaping () -> Void) ???
My macOS application that used focusedValues that was working correctly on Big Sur, is not working on Monterrey. I am using focused values for macOS menu like passing currently active document viewModel, and the focusedValues when retrived via @FocusedValue are always nil.
This breaks absolutelly the Main Menu commands on Monterrey.
Hello, there are currently many issues for MIDI FX Plugins and Audio Unit v3:
MIDI FX Plugins do not receive the host sample rate, there is no way to inherrit or react to sample rate changes made in Logic Pro X. (This affects severly plugins that calculate midi delta using the event.sampleTime)
MIDI FX Plugins that are instantiated as multiple instances on 2 or more tracks, the midi on other instances than selected track are passed and can be seen in plugin instance, however they are not played back later on instrument. This is a serious bug as If anybody instantiate Midi FX Plugin v3 on 2 or more instances, it breaks the playback of these tracks.
I have the same issue my Midi FX plugin that is AU v3 is appearing in Logic Pro X 8 times. Anybody has any fix for that?
Thanks for reply and the explanation, this is really great, I hope the issues will be fixed to be able to port apps to use fully SwiftUI. Something like this implementation is really needed as the responder chain do not fit the SwiftUI. Thanks.
Great, thank you !!!