Post

Replies

Boosts

Views

Activity

Reply to Should you access @State properties from an NSViewController (AppKit / SwiftUI Integration)?
Great, that's kind of what I was expecting. So a shared ViewModel like in the implementation below is the recommended way to marshal data between an NSViewController and a SwiftUI View? import AppKit import SwiftUI final class ViewModel: ObservableObject { @Published var details: String = "" } struct DetailsView: View { @ObservedObject var viewModel: ViewModel var body: some View { Text(viewModel.details) } } final class ViewController: NSViewController { private let viewModel: ViewModel init() { self.viewModel = ViewModel() super.init(nibName: nil, bundle: nil) } override func viewDidLoad() { let detailsView = DetailsView(viewModel: viewModel) view.addSubview(NSHostingView(rootView:detailsView)) } func updateDetails(_ details: String) { viewModel.details = details } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’25
Reply to Predictive code completion download failed
Same problem here. Updated to macOS 15.1 today and then downloaded Xcode 16.1 (16B40). On launch, Xcode attempted to download the predictive code model but failed. Also fails when download is invoked from Xcode - Settings - Downloads. This is the first attempt at downloading Xcode's predictive code model. Prior to today, laptop was running macOS 14. The operation couldn’t be completed. (ModelCatalog.CatalogErrors.AssetErrors error 1.) Domain: ModelCatalog.CatalogErrors.AssetErrors Code: 1 User Info: { DVTErrorCreationDateKey = "2024-10-28 20:15:42 +0000"; } -- Failed to find asset: com.apple.fm.code.generate_small_v1.tokenizer - no asset Domain: ModelCatalog.CatalogErrors.AssetErrors Code: 1 -- System Information macOS Version 15.1 (Build 24B83) Xcode 16.1 (23503) (Build 16B40) Timestamp: 2024-10-28T16:15:42-04:00
Oct ’24
Reply to Will the Virtualization Framework support iCloud accounts?
Sure thing, though as a perfect example of what I'm referring to, I actually can't log into Feedback Assistant within a virtual machine. Feedback Assistant's login screen simply reports "An error occurred during authentication." when I enter my Apple Developer credentials. I can, of course, log into Feedback Assistant from the host macOS instance, but not from within the guest instance. At the moment, my host is running Monterey while my guest is running Ventura. I'd like to spend more time testing Ventura and building software within it, but without access to iCloud or my developer account, it makes that goal almost impossible.
Topic: App & System Services SubTopic: Core OS Tags:
Jun ’22
Reply to What is the proper way to instantiate an observable ViewModel with init parameters in a SwiftUI View?
This question comes up so frequently that it would be extremely appreciated if someone on the SwiftUI team or a DTS representative could chime in on this. The vast majority of sample code and documentation assumes a view model can be created without any parameters to its initializer, which is not always the case. And in the Fruta example app a single Model is used for the entire application, which really isn't realistic for larger scale applications. I've resorted to the following design pattern but I remain unsure if this is considered a "correct" way to initialize an @StateObject property: struct ParentView: View { var body: some View { ChildView(viewModel: ChildViewModel(someValue: "foo")) } } class ChildViewModel: ObservableObject { init(someValue: Any) { } } struct ChildView: View { @StateObject var viewModel: ChildViewModel } This pattern appears to work correctly and doesn't require the small "hack" of using the underscore to initialize the @StateObject, which appears to be discouraged based on my reading of the documentation: StateObject.init(wrappedValue:) // You don’t call this initializer directly. Instead, declare a property with the  // @StateObject attribute in a View, App, or Scene, and provide an initial value: struct MyView: View { @StateObject var model = DataModel() }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’22