Post

Replies

Boosts

Views

Activity

macOS SwiftUI Table with contextMenu
Using SwiftUI's new Table container, how can I add a context menu that appears when Control-clicking a row? I can add the contextMenu modifier to the content of the TableColumn, but then I will have to add it to each individual column. And it only works above the specific text, not on the entire row: I tried adding the modifier to the TableColumn itself, but it shows a compile error: Value of type 'TableColumn<RowValue, Never, Text, Text>' has no member 'contextMenu' Here's what I have in terms of source code, with the contextMenu modifier in the content of the TableColumn: struct ContentView: View { @Environment(\.managedObjectContext) private var viewContext @FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \Item.name, ascending: true)]) private var items: FetchedResults<Item> @State private var sortOrder = [KeyPathComparator(\Item.name)] @State private var selection = Set<Item.ID>() var body: some View { NavigationView { Table(items, selection: $selection, sortOrder: $items.sortDescriptors) { TableColumn("Column 1") { Text("Item at \($0.name!)") .contextMenu { Button(action: {}) { Text("Action 1") } Divider() Button(action: {}) { Text("Action 2") } Button(action: {}) { Text("Action 3") } } } TableColumn("Column 2") { Text($0.id.debugDescription) } } .toolbar { ToolbarItem { Button(action: addItem) { Label("Add Item", systemImage: "plus") } } } if selection.isEmpty { Text("Select an item") } else if selection.count == 1 { Text("Selected \(items.first(where: { $0.id == selection.first! })!.id.debugDescription)") } else { Text("Selected \(selection.count)") } } } } So, how can I add a context menu to the entire row inside the Table?
3
0
4.3k
Mar ’22
SwiftUI: How to change List selected item color
iPadOS uses a different selection color when an external keyboard is connected. But the problem is that it doesn't change the text color to white, making it difficult to read: A simple List with NavigationLink produces this behavior by default: var body: some View { List { ForEach(searchResults) { item in NavigationLink(destination: ContentDetailView(item: item)) { ListItemView(item: item) } } } } I tried to improve text legibility by changing all Text colors to white when the cell is selected. But this doesn't work because the text becomes even more unreadable when no external keyboard is connected. Is there a way to change the selection color when an external keyboard is connected? Or maybe detect when an external keyboard is connected to manually change the text color for this specific case?
0
1
1.5k
Mar ’22
Transaction.latest(for:) returns nil in StoreKit 2
Using the Implementing a Store In Your App Using the StoreKit API sample code, I've successfully integrated my new APP with StoreKit 2. There is one problem though: when I call the method Transaction.latest(for:) to get the user’s latest transaction, it always returns nil. Here's the code snippet: guard let result = await Transaction.latest(for: myProductId) else { return false } Is this a bug with StoreKit 2, or am I doing something wrong? This happens on a physical device, running from Xcode. Thanks in advance.
4
0
2.3k
Jan ’22
SwiftUI view does not update when FetchRequest data changes from inside Action Extension
I'm sharing a Core Data store with my action extension, which adds data to it. My app has a SwiftUI view that presents this data, fetched with a FetchRequest: private struct VideosScrollView: View { @Environment(\.managedObjectContext) private var viewContext private var fetchRequest: FetchRequest<Video> init(sortOrder: String, tagIds: String, showWatched: Bool) { fetchRequest = Video.getFetchRequest(sortingBy: "addDate", with: sortOrder, showWatched: showWatched, tagIds: tagIds) } var body: some View { ScrollView { if fetchRequest.wrappedValue.isEmpty { ContentEmptyView() } else { ForEach(fetchRequest.wrappedValue) { item in VideoCellView(video: item) } } } } } After adding data from the action extension and going back to the app, the view is not updated. Only after CloudKit finished a sync is that the view notices something changed and updates itself. How can I force my SwiftUI view to update when data changes in the action extension?
1
0
1.2k
Dec ’21
How to reload widgets from the share sheet, via an Action Extension
My app has an action extension that allow users to collect and save links throughout the system. It also has a widget to show these links in the Home Screen. When adding links from the main app, I call WidgetCenter.shared.reloadAllTimelines() to reload all widgets, and everything works as expected. But when I add links from the action extension, widgets are not reloaded, even after calling WidgetCenter.shared.reloadAllTimelines(). Only when I go to the main app is that widgets do reload. How can I refresh my widgets for changes made via the Action Extension from the share sheet?
0
0
915
Dec ’21
Can't obtain the user's Apple Music token on macOS (Catalyst)
On a macOS app generated with Catalyst, the method SKCloudServiceController.requestUserToken(forDeveloperToken:completionHandler:) returns a SKErrorDomain. The error is: Error Domain=SKErrorDomain Code=0 "Ocorreu um erro desconhecido" UserInfo={NSLocalizedDescription=Ocorreu um erro desconhecido} Has something changed regarding this method on macOS or is this a bug?
9
0
2.4k
Dec ’21
macOS SwiftUI Table with contextMenu
Using SwiftUI's new Table container, how can I add a context menu that appears when Control-clicking a row? I can add the contextMenu modifier to the content of the TableColumn, but then I will have to add it to each individual column. And it only works above the specific text, not on the entire row: I tried adding the modifier to the TableColumn itself, but it shows a compile error: Value of type 'TableColumn<RowValue, Never, Text, Text>' has no member 'contextMenu' Here's what I have in terms of source code, with the contextMenu modifier in the content of the TableColumn: struct ContentView: View { @Environment(\.managedObjectContext) private var viewContext @FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \Item.name, ascending: true)]) private var items: FetchedResults<Item> @State private var sortOrder = [KeyPathComparator(\Item.name)] @State private var selection = Set<Item.ID>() var body: some View { NavigationView { Table(items, selection: $selection, sortOrder: $items.sortDescriptors) { TableColumn("Column 1") { Text("Item at \($0.name!)") .contextMenu { Button(action: {}) { Text("Action 1") } Divider() Button(action: {}) { Text("Action 2") } Button(action: {}) { Text("Action 3") } } } TableColumn("Column 2") { Text($0.id.debugDescription) } } .toolbar { ToolbarItem { Button(action: addItem) { Label("Add Item", systemImage: "plus") } } } if selection.isEmpty { Text("Select an item") } else if selection.count == 1 { Text("Selected \(items.first(where: { $0.id == selection.first! })!.id.debugDescription)") } else { Text("Selected \(selection.count)") } } } } So, how can I add a context menu to the entire row inside the Table?
Replies
3
Boosts
0
Views
4.3k
Activity
Mar ’22
SwiftUI: How to change List selected item color
iPadOS uses a different selection color when an external keyboard is connected. But the problem is that it doesn't change the text color to white, making it difficult to read: A simple List with NavigationLink produces this behavior by default: var body: some View { List { ForEach(searchResults) { item in NavigationLink(destination: ContentDetailView(item: item)) { ListItemView(item: item) } } } } I tried to improve text legibility by changing all Text colors to white when the cell is selected. But this doesn't work because the text becomes even more unreadable when no external keyboard is connected. Is there a way to change the selection color when an external keyboard is connected? Or maybe detect when an external keyboard is connected to manually change the text color for this specific case?
Replies
0
Boosts
1
Views
1.5k
Activity
Mar ’22
Transaction.latest(for:) returns nil in StoreKit 2
Using the Implementing a Store In Your App Using the StoreKit API sample code, I've successfully integrated my new APP with StoreKit 2. There is one problem though: when I call the method Transaction.latest(for:) to get the user’s latest transaction, it always returns nil. Here's the code snippet: guard let result = await Transaction.latest(for: myProductId) else { return false } Is this a bug with StoreKit 2, or am I doing something wrong? This happens on a physical device, running from Xcode. Thanks in advance.
Replies
4
Boosts
0
Views
2.3k
Activity
Jan ’22
SwiftUI view does not update when FetchRequest data changes from inside Action Extension
I'm sharing a Core Data store with my action extension, which adds data to it. My app has a SwiftUI view that presents this data, fetched with a FetchRequest: private struct VideosScrollView: View { @Environment(\.managedObjectContext) private var viewContext private var fetchRequest: FetchRequest<Video> init(sortOrder: String, tagIds: String, showWatched: Bool) { fetchRequest = Video.getFetchRequest(sortingBy: "addDate", with: sortOrder, showWatched: showWatched, tagIds: tagIds) } var body: some View { ScrollView { if fetchRequest.wrappedValue.isEmpty { ContentEmptyView() } else { ForEach(fetchRequest.wrappedValue) { item in VideoCellView(video: item) } } } } } After adding data from the action extension and going back to the app, the view is not updated. Only after CloudKit finished a sync is that the view notices something changed and updates itself. How can I force my SwiftUI view to update when data changes in the action extension?
Replies
1
Boosts
0
Views
1.2k
Activity
Dec ’21
How to reload widgets from the share sheet, via an Action Extension
My app has an action extension that allow users to collect and save links throughout the system. It also has a widget to show these links in the Home Screen. When adding links from the main app, I call WidgetCenter.shared.reloadAllTimelines() to reload all widgets, and everything works as expected. But when I add links from the action extension, widgets are not reloaded, even after calling WidgetCenter.shared.reloadAllTimelines(). Only when I go to the main app is that widgets do reload. How can I refresh my widgets for changes made via the Action Extension from the share sheet?
Replies
0
Boosts
0
Views
915
Activity
Dec ’21
Can't obtain the user's Apple Music token on macOS (Catalyst)
On a macOS app generated with Catalyst, the method SKCloudServiceController.requestUserToken(forDeveloperToken:completionHandler:) returns a SKErrorDomain. The error is: Error Domain=SKErrorDomain Code=0 "Ocorreu um erro desconhecido" UserInfo={NSLocalizedDescription=Ocorreu um erro desconhecido} Has something changed regarding this method on macOS or is this a bug?
Replies
9
Boosts
0
Views
2.4k
Activity
Dec ’21