Post

Replies

Boosts

Views

Activity

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,
1
0
1.1k
Aug ’15
"isWritableFileAtPath" returns "true" for files in a shared readonly iCloud Drive folder
Hello,My app supports to open file via UIDocumentPickerViewController, and the app needs to detect if the opened file is writable.We are using the "isWritableFileAtPath" method to detect if the file is writable, but iCloud Drive behaviors strangly:----Case one:Sharing a file directly with readonly permission from iCloud account A to iCloud account B, "isWritableFileAtPath" return "false" on the device of the B user - that's what we expected.----Case two:Sharing a FOLD with readonly permission from iCloud account A to iCloud account B, "isWritableFileAtPath" for a file in the shared folder returns "true" on the device of the B user - that's NOT what we expected.=============Would you please help us on it?- Is it a bug of the iCloud Drive?- Or if there is another way to detect if the app has permission to write the file opened using UIDocumentPickerViewController ?Thanks,Philip
1
0
1.4k
May ’20
Catalyst and Native using SwiftUI to develop a new app for the macOS?
We believe it's time to start developing apps using SwiftUI by watched the WWDC20 "Keynote" and "Platforms State of the Union". We are planning to develop an app for the iOS and macOS, and we'd like to macOS app to be fine tuned to use the macOS native capabilities. I am wondering what's the recommend way that @Apple prefer to do for the new app using SwiftUI for developing the macOS app, catalyst or native? (sharing code is not the key, we can copy :) ) Thank you.
3
0
3.6k
Jun ’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.3k
Jun ’20
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
1k
Sep ’20
"*** 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 "*** 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
14k
Jun ’21
.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.
0
0
910
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() } }
0
0
583
Jun ’22
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
2k
Jun ’22
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.4k
Jun ’23
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
817
Jun ’23