Post

Replies

Boosts

Views

Activity

SwiftData Multiple ModelConfigurations
A ModelContainer with two configurations for two seperate models with one set to isStoredInMemoryOnly:false and the other one isStoredInMemoryOnly:true crashes after insertion. Anyone git this to work? import SwiftData @main struct RecipeBookApp: App { var container: ModelContainer init() { do { let config1 = ModelConfiguration(for: Recipe.self) let config2 = ModelConfiguration(for: Comment.self, isStoredInMemoryOnly: true) container = try ModelContainer(for: Recipe.self, Comment.self, configurations: config1, config2) } catch { fatalError("Failed to configure SwiftData container.") } } var body: some Scene { WindowGroup { ContentView() .modelContainer(container) } } } struct ContentView: View { @Environment(\.modelContext) private var context @Query private var recipes: [Recipe] @Query private var comments: [Comment] var body: some View { VStack { Button("Insert") { context.insert(Recipe(name:"Test")) context.insert(Comment(name:"Test")) } List(recipes){ recipe in Text(recipe.name) } List(comments){ comment in Text(comment.name) } } .padding() .onAppear(){ context.insert(Recipe(name:"Test")) context.insert(Comment(name:"Test")) } } } @Model class Recipe { internal init(name:String ) { self.name = name } var id: UUID = UUID() var name: String = "" } @Model class Comment { internal init(name:String ) { self.name = name } var id: UUID = UUID() var name: String = "" }
2
0
443
Sep ’24
Open custom UTType from messages.
I've declared a custom extension in my plist for "Document types", "Exported Type Identifiers" and "Imported Type Identifiers". I'm sending the file via messages with the right extension, the file with custom extension shows in messages when received. However when I tap on it in messages nothing happens. I know UTType is a fiddly subject, this question has been asked many times before from different angles. Instead of me sending my plist etc does anyone have a working project that exports a custom file extension that is openable in messages when tapping it? If so any possibility to share this project in Git so we can have a master example so devs don't have to go thru this painful process?
0
0
408
Nov ’23
TipKit with NavigationSplitView
I'm facing multiple issues with TipKit. Let's start with this one. It's a NavigationSplitView, side bar has a toolbar button with a .popoverTip as well as the detail view. When launched (iPad landscape for example) only the sidebar tip shows, which is understandable because you wouldn't want two tips to show. However when the sidebar tip is .invalidate the second tip doesn't show. One needs to restart the app. How can I show the detail tip after the sidebar tip has been .invalidate? import SwiftUI import TipKit @main struct TestApp: App { let firstTip = FirstTip() let secondTip = SecondTip() var body: some Scene { WindowGroup { NavigationSplitView { List(1..<3) { i in NavigationLink("Row \(i)", value: i) } .toolbar { ToolbarItem { Button { firstTip.invalidate(reason: .actionPerformed) } label: { Image(systemName: "fireworks") } .popoverTip(firstTip, arrowEdge: .top) } } .navigationDestination(for: Int.self) { Text("Selected row \($0)") } .navigationTitle("Split View") } detail: { Text("Please select a row") .toolbar { ToolbarItem { Button { secondTip.invalidate(reason: .actionPerformed) } label: { Image(systemName: "trash") } .popoverTip(secondTip, arrowEdge: .top) } } } } } init() { try? Tips.resetDatastore() try? Tips.configure([ .datastoreLocation(.applicationDefault), .displayFrequency(.immediate) ]) } } struct FirstTip: Tip { var title: Text {Text("FirtTip")} var message: Text? {Text("FirtTip")} var image: Image? {Image(systemName: "trash")} } struct SecondTip: Tip { var title: Text {Text("SecondTip")} var message: Text? {Text("SecondTip")} var image: Image? {Image(systemName: "trash")} }
1
0
763
Oct ’23
SwiftUI Navigation Title Renaming on MacOS
According to Apple's docs title renaming should also work on MacOS: You can provide a text binding to the navigation title modifier and SwiftUI will automatically configure the toolbar to allow editing of the navigation title on iOS or macOS. It works fine on iOS and iPadOS but no go on MacOS. Anyone got it to work?
0
0
426
Sep ’23