Post not yet marked as solved
Hi,
using the following ContentView in a SwiftUI app on macOS I would expect that the state of the toggle persists across application launches:
struct ContentView: View {
@SceneStorage("Toggle") var onOrOff: Bool = false
var body: some View {
VStack {
Toggle("Will it persist?", isOn: $onOrOff)
.padding()
}
}
}
To my surprise it does not persist. Am I wrong about how @SceneStorage should work? (I am trying this on the lates macOS/Xcode versions)
Does @SceneStorage work for anybody on macOS?
Thanks for your feedback!
Cheers, Michael
Post not yet marked as solved
How does one declare a TableColumn with a nullable field?
I have a Book model with several nullable fields:
struct Book: Codable, Equatable, Identifiable {
// ...
let productURL: String?
// ...
}
This is how I'm trying define the corresponding TableColumn:
TableColumn("Product URL", value: \.productURL) { book in
Text(String(book.productURL ?? ""))
}
Though this results in several errors:
Referencing initializer 'init(_:value:comparator:content:)' on 'TableColumn' requires that 'Book' inherit from 'NSObject'
Referencing initializer 'init(_:value:comparator:content:)' on 'TableColumn' requires that 'Book' inherit from 'NSObject'
Referencing initializer 'init(_:value:comparator:content:)' on 'TableColumn' requires the types 'KeyPathComparator' and 'SortDescriptor' be equivalent
Referencing initializer 'init(_:value:comparator:content:)' on 'TableColumn' requires the types 'KeyPathComparator' and 'SortDescriptor' be equivalent
Other, non-nullable columns work just fine. For example:
TableColumn("ID", value: \.id) { book in
Text(String(book.id))
}
TableColumn("Slug", value: \.slug)
TableColumn("Category", value: \.category)
TableColumn("Title", value: \.title)
// ...
Post not yet marked as solved
I am using SwiftUI for Mac OS and so far I have not been able to implement tap gestures. I want to double click on a row of the Table and have that perform an action using the contents of that row. Does anyone know if it is even possible to use the .onTapGesture or anything similar to a SwiftUI Table? Any help is appreciated!
Thanks!
Post not yet marked as solved
I'm currently learning on creating an app using swiftui. The idea of the app that I'm creating will need to be able to change values at any given moment. Is it possible to create a website that will only give access to certain users to change the values on the app instantly and not have to submit the changes for Apple to approve it? If this is possible what coding language do I need to learn? Any feedback is appreciated!
Post not yet marked as solved
I am trying to use import from iPhone option as shown in WWDC session.
I added code
WindowGroup {
ContentView()
.environment(\.managedObjectContext, persistenceController.container.viewContext)
}
.commands {
ImportFromDevicesCommands()
}
ContentView.swift is
List {
ForEach(items) { item in
NavigationLink {
Text("Item at \(item.timestamp!, formatter: itemFormatter)")
} label: {
Text(item.timestamp!, formatter: itemFormatter)
}
}
.onDelete(perform: deleteItems)
}
.importsItemProviders([.image,.png,.jpeg,.rawImage], onImport: { providers in
print("checking reachability")
return true
})
The importsItemProviders block itself is not executed and not printing anything.
In addition I am getting alert The operation couldn’t be completed. (Cocoa error 66563.)
Is there anything to add for making this functionality work ?
Post not yet marked as solved
In the current version of the Garden app, when you add a new Plant, the variety is 'New Plant' and the days to maturity is zero.
How can we change the code (and replacing the Text by TextField) to make these two fields for instance editable.
My question comes from the fact that in the table, we use plants computed property that take all the plants from the garden, and the filter using the search text and sort them.
How can we change that to have binding to plants and then use that in the table?
Regards
Vincent
Post not yet marked as solved
Hi,
I'm trying to use Table in an app sort of similar to the garden example but imagine if there was a third view in the NavigationView for a third column.
And then imagine that if you selected a single plant in the middle table, a sort of detail inspector would appear in the third position with the data from your selection, updating as the selection in the middle table changed.
I'm struggling a bit to get this working. I've tried:
Wrapping the table column content closure's contents in a NavigationLink. This sort of works but it styles things oddly in the table column and as I scroll around, it seems to trigger on it's own, I'm guessing as cells are re-used or something behind the scenes. This feels wrong.
Moving row creation into the rows: parameter with TableRow but the only modifier there is for drag and drop, there's no onTapGesture or similar.
Watching for changes to the selected item via the binding and then acting on it then - this fires when I select stuff and I can get the related model object but I can't put a NavigationLink in there as it's outside of the view hierarchy so I'm not sure how to act on it.
I'm guessing there's some other way to handle this that I'm simply not thinking of but if anyone has any pointers, much appreciated!
Post not yet marked as solved
In the Sidebar, the badge doesn't show up for me. This is also the case with the end product:
ForEach(store.gardens(in: store.currentYear)) { garden in
Label(garden.name, systemImage: "leaf")
.badge(garden.numberOfPlantsNeedingWater)
}