Post

Replies

Boosts

Views

Activity

Comment on ObservableObject Array data not updating
Oops, I posted my answer at 7am and wasn't wide awake. When using a singleton **static let shared = DataModel() ** in the data model instead of using @StateObject in the root view, you refer to it (and get state changes) by using @ObservedObject var dataModel = DataModel.shared in the view where you are handing the @Published vars (e.g. arrayInt). Apologies, Michaela
Aug ’21
Comment on slots to hangman game
A @StateObject var is like a @State var, except that @State only applies to the View where it's defined whereas a @StateObject var applies (with the right conventions) across all views. Here, State refers toSwiftUI, not CoreData. This is important where 2 or more views need access to the data model, because if you use @State var dataModel = DataModel() in both (all) views then separate and different versions of dataModel are created - i.e. they don't "talk" to each other. So, in the example I gave you, you will need to put @StateObject var ... in the App view - as per my earlier comment. Regards, Michaela
Aug ’21
Comment on slots to hangman game
You're welcome Kenn. I'm retired and currently stuck at home in a COVID lockdown, so it was good to exercise my mind. Also, I'm not sure if you're familiar with @StateObject. When Xcode created your project, it probably created a View named somethingApp. Putting @StateObect into this View allows a single instance of DataModel to be passed to all subsequent views: @StateObject var dataModel = DataModel(). then use .environmentObject(dataModel) after the ContentView() line The @EnvironmentObject var dataModel: DataModel line in my sample code picks up this reference from the @StateObject in the App view. Cheers, Michaela
Aug ’21
Comment on Identifiable ID
Sorry, I should've been more explicit, beyond saying that the the Identifiable and var id weren't needed. Making something Identifiable means that it must have a property called "id". You can also use the id: parameter with List() in SwiftUI, but be aware that having a List in a ScrollView doesn't work - presumably because List is also a ScrollView. I'm happy to help out: I'm retired (in my seventies) and write apps for my own needs and to keep my mind active, so giving back is good for me. Best wishes, Michaela
Aug ’21
Comment on SwiftUI Map mapType hybrid / satellite - possible?
For some reason inline code is not working in Comments (Monterey Beta issue?). The code that works on the very first launch of the app is .onAppear(perform: {             MKMapView.appearance().mapType = mapStyle             MKMapView.appearance().showsScale = true             MKMapView.appearance().showsCompass = true         }) Thereafter, until the app is killed and relaunched, the options are reset to default. My understanding is that many features (such as mapType, showsScale, showsCompass) are unavailable in Map() and any solution, other than an official enhancement, will be a fudge that's prone to future breakage.
Aug ’21
Comment on Activity recognition using core motion
No, it's better that you create your own project in whatever version of Xcode that you have, adapting accordingly. I think (from memory) that Xcode 12 onwards creates SwiftUI apps by default, so you would only need to create your new project and then: Create a Swift file called DataModel and add the code I've given; Modify your new project's App file to add the @StateObject and .environmentObject lines I've given; Modify ContentView to be as I've described; Add your Plist entry as described.
Jul ’21