Post

Replies

Boosts

Views

Activity

iPadOS 26 Menu Bar Questions
We’re currently working on adding support for a Menu Bar in a cross-platform app built with SwiftUI, aiming to reuse the existing macOS menu bar implementation for iPadOS. The basic functionality is working well, but we’ve run into several challenges due to missing APIs—or ones we may have overlooked. We’d appreciate any insights or suggestions on the following issues: (Xcode 26 beta 3, iPadOS 26 beta 3) Command Handlers (Copy, Cut, Paste, Delete) On iOS/iPadOS, handlers like onCopyCommand, onCutCommand, onPasteCommand, and onDeleteCommand are unavailable. Since we also can’t hide the default context menus, we’re unsure how to properly implement these functions. How can we best support copy/paste behavior on iPadOS using the menu bar? Undo/Redo Support Undo and redo work as expected on macOS, but on iPadOS, the menu items are always grayed out—even though undo/redo functionality is available in the app. Is there a recommended way to enable these items in the menu bar for iPadOS? Hiding Unused Menu Items We’d like to hide system-provided menu items that aren’t relevant to our app, such as: Open… Select All Customize Toolbar… New Window, Show All Windows, Open Windows, etc. Is there a way to control which default items appear in the menu bar? App Settings Menu Is it possible to customize the App Settings menu so it opens our app’s settings view inside the app (similar to a SwiftUI .sheet or navigation push)? Lastly We couldn’t find a comprehensive example that covers most use cases for implementing a custom menu bar on iPadOS using SwiftUI. If there’s an open-source project or documentation that you’ve found helpful, we’d love to see it. Thanks in advance for your help!
Topic: UI Frameworks SubTopic: SwiftUI
1
0
98
2w
Throttling and Debouncing
I want to use Throttling and Debouncing to handle the inputs from the user. These are common techniques to reduce the number of events that are triggered by the inputs. I know how to implement them with the ObservableObject protocol and Combine framework. However, I am trying to migrate to the @Observable property wrapper, which is a new feature of SwiftUI. I cannot find a way to support Throttling and Debouncing with @Observable. Does anyone have any ideas or suggestions on how to solve this problem?
1
1
1k
Jun ’23
CKSyncEngine & SwiftData
I am working on a SwiftUI application that needs to sync data across multiple devices using CloudKit. I am trying to decide between two options: CKSyncEngine with a custom model SwiftData plus CloudKit container. This decision is crucial for me because the application I am developing is using tree structured data and the relationship between the data is very complex. I would appreciate your guidance on which option is better suited for my needs. One of the benefits of using SwiftData is that it has a lot of interesting features that can save me a lot of development time, such as automatic migrations, batch operations, predicates, sorting, grouping, etc. However, one of the drawbacks is that it may not be flexible enough to handle the complex data display logic that I need for my application. For example, I need to show different views depending on the level and type of the tree nodes, and I also need to perform some calculations and transformations on the data before displaying it. I am afraid that using SwiftData will lead to more complexity and uncertainty when implementing these features, and there may be performance issues as well. Another factor that I need to consider is the future support and development of these options. I believe SwiftData will have a good future because it is based on Apple's frameworks and technologies. However, I don't know if CKSyncEngine will be valued in the long run because it is a third-party framework that may not be updated or maintained regularly. In conclusion, I am still unsure whether to use CKSyncEngine or SwiftData for my SwiftUI application that needs CloudKit sync. Both options have their pros and cons, and I need to weigh them carefully according to my requirements and preferences. I would love to hear your opinion on this matter. Thank you for your time and attention.
5
0
1.8k
Jun ’23
Drag file from app to Finder on macOS
Is it possible under macOS to drag a file from an app into the Finder?  For example, I want to drag a CSV file from the app to the Finder, but the following code does not work. static var transferRepresentation: some TransferRepresentation {         FileRepresentation(exportedContentType: .commaSeparatedText) {_ in             SentTransferredFile(Bundle.main.url(forResource: "Demo", withExtension: "csv")!)         } } And I changed the exportedContentType to ".fileUrl", ".url" and ".data" but the code still does not work.
5
1
2.2k
Jun ’22
focusable modifier does not work on Ventura
It works on Monterey, but not work on Ventura. struct ContentView: View { @FocusState private var focus: FocusableElement? @FocusedValue(\.focusedElement) var focusElement var body: some View { VStack(spacing: 30) { HStack { GroupBox { Circle() .focusable() .focused($focus, equals: .circle) .focusedValue(\.focusedElement, .circle) .frame(width: 100, height: 100) .padding() Text(focus == .circle ? "Selected" : "Not selected") } .onTapGesture { focus = .circle } GroupBox { Rectangle() .focusable() .focused($focus, equals: .rectangle) .focusedValue(\.focusedElement, .rectangle) .frame(width: 100, height: 100) .padding() Text(focus == .rectangle ? "Selected" : "Not selected") } } .onTapGesture { focus = .rectangle } Text("Focused Element: \(focusElement?.rawValue ?? "None")") } .padding() .frame(width: 500, height: 300) } } enum FocusableElement: Equatable, Hashable { case rectangle case circle } enum Selection: String, Hashable { case none case rectangle case circle } extension FocusedValues { struct FocusedElement: FocusedValueKey { typealias Value = Selection } var focusedElement: FocusedElement.Value? { get { self[FocusedElement.self] } set { self[FocusedElement.self] = newValue } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }
1
0
653
Jun ’22
.commandsRemoved() does not work for the first scene.
.commandsRemoved() does not work for the Window and WindowGroup scenes if it’s the primary group (first one). Then I tried to add new menu using the code .commands {       CommandGroup(replacing: .newItem) {           Button("New Document") {               newDocument { TestDocument() }           }           .keyboardShortcut("n") } But app crashed with error " Expected subclass override" The test app is a document-based app, with a welcome window using the new Window scene.
1
0
989
Jun ’22
"xxx is only available in iOS 15.0 or newer"
I created a new iOS project targeting iOS 15 using Xcode 13.0 beta (13A5154h) on Big Sur to test some new SwiftUI features.  Xcode shows me the error like "xxx is only available in iOS 15.0 or newer" for all new API for iOS 15.  The project target is iOS 15  I tried to create another project again, same problem.  Would you please help to fix it?  Thanks a lot! Philipp
2
0
16k
Jun ’21
Menu - .infinity width does not work
I tried to create a menu item with full width of the screen, as following the code: VStack { Menu { Button("Option 1", action: actionOne) Button("Option 2", action: actionTwo)     } label: {          Label("Options", systemImage: "paperplane")                .padding()     } .frame(maxWidth: .infinity) } And tried to change the label using HStack VStack { Menu { Button("Option 1", action: actionOne) Button("Option 2", action: actionTwo)     } label: {          HStack { Text("Options") Spacer() } .padding()     } .frame(maxWidth: .infinity) } And tried to customize using MenuStyle. But the menu label renders NOT in the full width using all preceding the codes. Would you please help to check and share me the solution? Thanks, Philip
0
0
1.1k
Sep ’20
CommandGroup (keyboardShortcut) does not work on iPad simulator
The keyboard shortcut does not work on the iPadOS 14 simulator using following the code. @main struct DemoApp: App {     var body: some Scene {         WindowGroup {             Text("Demo Keyboard Shotcuts")         }         .commands {             CommandGroup(before: .sidebar) {                 Button("Test Keyboard", action: { print("keyboard shortcut - command + k") })                     .keyboardShortcut("[")             }         }     } } Would you please help us to know what's the problem? From the WWDC session "What's new in SwiftUI", the keyboard shortcut should work on iPad. Thank you.
3
0
1.4k
Jun ’20
NSView and Events
By default, the events (mouse/cursor/scroll...) are bypassed to the controls under the NSView, for example, there are one NSView (named A) and one NSTextField (named B). A and B are at same place, and A is above B.All mouse events passed to B (TextField)Cursor has been changed as "I", not the default cursor as expectedScroll mouse will scroll B (the textfield if multiple lines)I'd like that if mouse on A (the NSView), all the events are not passed to B. So I subclass NSView for A as the code following:// ------------------------------------------------class ResponsibleView: NSView { override func acceptsFirstMouse(theEvent: NSEvent?) -> Bool { return true } override var acceptsFirstResponder : Bool { return true } override func mouseUp(theEvent: NSEvent) { } override func resetCursorRects() { superview?.resetCursorRects() self.addCursorRect(self.bounds, cursor: NSCursor.arrowCursor()) } override func scrollWheel(theEvent: NSEvent) { }}// ------------------------------------------------Now there is a problem on cursor - the cursor is not stable, sometimes the cursor appears correctly, but sometimes incorrect. Would you please help to check following my questions?- Is there simple solution to avoid events bypassing NSView?- Why the cursor is too strange, how to make it be stable?- Why the cocoa for OSX makes things too complicated and not be intuitive? ( I am new for OSX development), is there any modern UI solution for OSX like XAML ...Thanks,
Topic: UI Frameworks SubTopic: AppKit Tags:
2
0
1.2k
Aug ’15