Post

Replies

Boosts

Views

Activity

Reply to RealityView update closure
Well, as seems to be all too often and embarassingly the case - ask a question in public, and suddenly the answer reveals itself... As it turns out I wasn't actually removing all objects in the update: closure and then replacing them - I was adding rebuilding them in my graph but not in the RealityView update: closure. Dumb oversight. TL;DR: I was expecting the @Published values to automagically update the 3D content - much the same way that SwiftUI automatically updates 2D textfields and such. That isn't what happens in the RealityView update: closure. So, the solution was simple: } update: { updateContent in updateContent.entities.removeAll() graph.renew() for element in graph.all { updateContent.add(element) } } where graph is a custom object that contains my RealityKit scene.
Jul ’23
Reply to Recomended hardware requirements.
Be fine for what - development? No way is 8 GB enough. I've got 2 SwiftUI apps in the AppStore, and both were developed on a 2020 M1 MacBook Air with 16GB RAM. Working with Xcode 15 beta 2 and VisionOS simulator, it comes to a crawl. My best guess is that this is a memory issue more than a processor issue. Bottom line: the M2 Mac mini would most likely be fine, but DEFINITELY buy the most RAM you can.
Jun ’23
Reply to Cannot use instance member within property initializer
To make it explicit, this works: @main struct SwiftDataFlashCardSample: App { let container: ModelContainer init() { let schema = Schema([Card.self]) let config = ModelConfiguration(schema: schema, cloudKitContainerIdentifier: "iCloud.org.your.name") var contain: ModelContainer? = nil do { contain = try ModelContainer(for: schema, config) } catch { print("couldn't create ModelContainer()") } self.container = contain! } var body: some Scene { WindowGroup { ContentView() } .modelContainer(container) } } and, as normal, add Capabilities iCloud.cloudKit and BackgroundModes.Remote notifications.
Jun ’23
Reply to Access Core Data ModelContainer with SwiftData
This worked: @main struct SwiftDataFlashCardSample: App { let container: ModelContainer init() { let schema = Schema([Card.self]) let config = ModelConfiguration(schema: schema, cloudKitContainerIdentifier: "iCloud.org.your.name") var contain: ModelContainer? = nil do { contain = try ModelContainer(for: schema, config) } catch { print("couldn't create ModelContainer()") } self.container = contain! } var body: some Scene { WindowGroup { ContentView() } .modelContainer(container) } } and, as normal, add Capabilities iCloud.cloudKit and BackgroundModes.Remote notifications.
Jun ’23
Reply to In swiftUI TextField ,can we have some property similar to textfield.text in case of UIkit's TextField so that we do not have to explicitly mantain a State var to hold textfield value?
I transitioned from UIKit based coding to SwiftUI coding 2 years ago. SwiftUI is a completely different mindset, and it can be awkward to get SwiftUI to do UIKit kinds of things. With respect to TextField delegate methods and SwiftUI state variables - one way of thinking about it that worked for me was to gather together all of the data that you need to paint your view, and put that into either State variables or a data object. Example, instead of allowing the name, address, city and state TextFields to hold the data, it's better to define an Address struct that has those same data fields. Then, your SwiftUI app just paints the values that are in the Address struct. Here's something else that really helped me make the transition: in UIKit programming, we tend to think of a TextField as having its own behaviors - like it holds the data for the name or address, and when the user types in that field, then the Textfield is responsible for updating it's value. In addition, it may be responsible for communicating that change to other objects in your app. In contrast, in SwiftUI, it's easiest to think about how the SwiftUI system throws away and re-creates any views whose data is no longer supporting the way the view is being painted. The data changes, then the View is discarded and re-created. My suggestion would be to watch WWDC23's "Build an app with SwiftData" and just notice how different it is from UIKit. SwiftUI has evolved tremendously over the past 3 years, and it's now awesome expressive - but in it's own, unique way.
Jun ’23
Reply to Some of my AppShortcut phrases work, but some launch Safari?
Here's another piece of the puzzle... I added another invocation to AppShortcut.phrases "show my top (.applicationName) cards" - and instead of doing the right thing or even launching Safari, this phrase launches a Siri disambiguation showing all the credit cards I have defined in my Apple Wallet. Further circumstantial evidence that Siri is pre-disposed to satisfying Apple-defined Intents before mine.
Feb ’23
Reply to iOS 16 - how to get more than 1 AppIntents / AppShortcut
I've hacked my way into a solution... turns out that: I only need to call .updateAppShortcutParameters() once that call to .updateAppShortcutParameters() needs to include an AppShortcut(intent:, phrases:) call for each AppIntent I've written the AppShortcutsProvider's appShortcuts:[AppShortcut] array is initialized in a way that I was not expecting... ie, you don't need []s around nor commas between array elements so, this is what it looks like: static var appShortcuts: [AppShortcut] { AppShortcut(intent:IntentOne(), phrases:["phrase 1"] // no commas! AppShortcut(intent:IntentTwo(), phrases:["phrase 2"] }
Feb ’23