[Code-Along] SwiftUI on the Mac: The finishing touches

RSS for tag

Discuss the WWDC21 session [Code-Along] SwiftUI on the Mac: The finishing touches.

Posts under wwdc21-10289 tag

8 Posts

Post

Replies

Boosts

Views

Activity

How to declare a TableColumn with nullable field?
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) // ...
8
0
3.5k
Nov ’23
ImportFromDevicesCommands - The operation couldn’t be completed. (Cocoa error 66563.)
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 ?
3
0
1.9k
Oct ’23
@SceneStorage not working on macOS
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
4
0
2.5k
Sep ’23
Is there a way to interact with your swiftui code through a website?
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!
0
0
502
Dec ’21
How to make the Table cell editable
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
2
0
1.3k
Oct ’21
Using Table Selection to Populate Other View
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!
6
0
2.4k
Oct ’21
How to declare a TableColumn with nullable field?
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) // ...
Replies
8
Boosts
0
Views
3.5k
Activity
Nov ’23
ImportFromDevicesCommands - The operation couldn’t be completed. (Cocoa error 66563.)
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 ?
Replies
3
Boosts
0
Views
1.9k
Activity
Oct ’23
@SceneStorage not working on macOS
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
Replies
4
Boosts
0
Views
2.5k
Activity
Sep ’23
is it possible to use gestures with SwiftUI Table?
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!
Replies
2
Boosts
0
Views
2.4k
Activity
Jan ’22
Is there a way to interact with your swiftui code through a website?
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!
Replies
0
Boosts
0
Views
502
Activity
Dec ’21
How to make the Table cell editable
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
Replies
2
Boosts
0
Views
1.3k
Activity
Oct ’21
Using Table Selection to Populate Other View
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!
Replies
6
Boosts
0
Views
2.4k
Activity
Oct ’21
Does the `.badge` modifier work for anyone?
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) }
Replies
3
Boosts
0
Views
1.3k
Activity
Aug ’21