Post

Replies

Boosts

Views

Activity

Reply to Weird crashes when accessing Swift Array
[quote='796453022, DTS Engineer, /thread/760029?answerId=796453022#796453022'] This shows how the ns as! [MyElement] cast is done lazily [/quote] Thanks, this already helped me reproduce and fix the second crash. The array was coming from a token field's objectValue. Regarding the first crash, I noticed something strange. The crash report seems to imply that a particular method called another one, which is impossible. Let me show and explain to you the rest of the stacktrace: ... Code Type: ARM-64 Parent Process: launchd [1] User ID: 501 Date/Time: 2024-07-18 14:59:40.4375 +0800 OS Version: macOS 15.0 (24A5289h) ... Crashed Thread: 0 Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x00000001045048b8 Termination Reason: Namespace SIGNAL, Code 5 Trace/BPT trap: 5 Terminating Process: exc handler [1771] Thread 0 Crashed: 0 MyApp 0x00000001045048b8 specialized Collection.map<A>(_:) + 596 1 MyApp 0x00000001045011e4 MyViewController.validateToolbarButtons() + 648 (MyViewController.swift:742) ... 12 MyApp 0x00000001044fcef4 MyViewController.myOtherAction(_:) + 184 (MyViewController.swift:455) 13 MyApp 0x00000001044fff28 @objc MyViewController.myModalAction(_:) + 80 14 AppKit 0x000000019e2ae13c -[NSApplication(NSResponder) sendAction:to:from:] + 460 15 AppKit 0x000000019e375b08 -[NSMenuItem _corePerformAction] + 372 16 AppKit 0x000000019ea4be30 _NSMenuPerformActionWithHighlighting + 152 17 AppKit 0x000000019e3ad5d0 -[NSMenu performActionForItemAtIndex:] + 200 18 AppKit 0x000000019e3ad4f0 -[NSMenu _internalPerformActionForItemAtIndex:] + 76 19 AppKit 0x000000019ea4204c +[NSCocoaMenuImpl _performActionForMenuItem:] + 176 20 AppKit 0x000000019e84ff58 -[NSMenuTrackingSession _performPostTrackingDismissalActions] + 268 21 AppKit 0x000000019e84fc60 -[NSMenuTrackingSession startRunningMenuEventLoop:] + 1332 22 AppKit 0x000000019e84f6d0 -[NSMenuTrackingSession startMonitoringEvents:] + 256 23 AppKit 0x000000019efe5d78 -[NSContextMenuTrackingSession startMonitoringEvents:] + 144 24 AppKit 0x000000019e8048f8 +[NSContextMenuImpl presentPopup:fromView:withContext:animated:] + 848 25 AppKit 0x000000019ea4d5ec _NSPopUpMenu + 2128 26 AppKit 0x000000019ea51cbc -[NSCocoaMenuImpl _popUpContextMenu:withEvent:forView:withFont:] + 304 27 AppKit 0x000000019e429acc -[NSMenu _popUpContextMenu:withEvent:forView:withFont:] + 208 28 AppKit 0x000000019ece4658 -[NSView _showMenuForEvent:] + 72 29 AppKit 0x000000019e425ff4 -[NSView rightMouseDown:] + 76 30 AppKit 0x000000019e7225e0 -[NSControl _rightMouseUpOrDown:] + 352 31 AppKit 0x000000019ed81ec4 _routeRightMouseDownEvent + 264 32 AppKit 0x000000019e2348f8 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 420 33 AppKit 0x000000019e234584 -[NSWindow(NSEventRouting) sendEvent:] + 284 34 AppKit 0x000000019ea1f568 -[NSApplication(NSEventRouting) sendEvent:] + 1656 35 AppKit 0x000000019e632b78 -[NSApplication _handleEvent:] + 60 36 AppKit 0x000000019e100914 -[NSApplication run] + 520 37 AppKit 0x000000019e0d7094 NSApplicationMain + 888 38 MyApp 0x000000010446ca80 main + 128 (main.swift:12) 39 dyld 0x000000019a16b274 start + 2840 The ellipsis only hides methods from my own classes. Directly below it, it would seem that @objc MyViewController.myModalAction(_:), which shows an app modal window, somehow calls MyViewController.myOtherAction(_:), but myOtherAction can only be called by a menu or the press of a toolbar button which are both disabled by the modal window shown by myModalAction. Does this mean that myOtherAction is called somehow when the modal window opened by myModalAction is closed? Another interesting point: I don't know why myModalAction is prefixed with @objc, since both are declared as @IBAction func methodName(_ sender: Any). The only difference is that myModalAction is set as a table view's doubleAction, but from the rest of the stacktrace it seems like myModalAction is called by a menu.
Jul ’24
Reply to How to link multiple text views to a single text storage in TextKit 2
Thanks. The part I was missing is the one the documentation for NSTextContentManager doesn't mention, which is that it is an abstract class whose (apparently) only concrete subclass is NSTextContentStorage, which has a textStorage property. guard let textStorage: NSTextStorage = (textLayoutManager?.textContentManager as? NSTextContentStorage)?.textStorage else { return } The sample code also changes the textStorage inside the block passed to textContentManager.performEditingTransaction(_:), which the documentation doesn't seem to explain why it's necessary.
Jun ’24
Reply to Getting inode number from URL
I just wanted to add that for some reason the order of imports inside the test files is important in some cases. I have to write: @testable import MyApp import XCTest Inverting those two lines causes several compiler errors inside the bridging header file: Redefinition of 'vtype' Redefinition of enumerator 'VBAD' Redefinition of enumerator 'VBLK' ... I have no idea why this happens, as in another project with the exact same bridging header file the order of imports seems to be irrelevant and doesn't cause any compiler errors.
Jun ’24
Reply to NSTableView - How can the background color of the row views be changed dynamically?
NSTableRowView has a property backgroundColor, but this is also used by AppKit when you set tableView.usesAlternatingRowBackgroundColors = true. The only way I could make it work was by returning a custom row view subclass and dynamically returning a custom background color. class MyRowView: NSTableRowView { var myBackgroundColor: NSColor? override var backgroundColor: NSColor { get { return myBackgroundColor ?? super.backgroundColor } set { super.backgroundColor = newValue } } } and in the delegate func outlineView(_ outlineView: NSOutlineView, didAdd rowView: NSTableRowView, forRow row: Int) { if myCondition { (rowView as! MyRowView).myBackgroundColor = myColor } }
Jun ’24
Reply to Share settings from SwiftUI in-app settings view to other views
I have more than 10 variables, of different types. Your suggestion of multiplexing doesn't work in this case. I have something like this, where I want to bind ContentView.var1 to SettingsView.var1, for each of the var listed in SettingsView, and possibly to other views as well. struct ContentView: View { var body: some View { VStack { if var1 { Text("Text") } } SettingsView() } } struct SettingsView: View { @AppStorage("var1") private var var1 = false @AppStorage("var2") private var var2 = true @AppStorage("var3") private var var3 = false @AppStorage("var4") private var var4 = MyType.Nested.value @AppStorage("var5") private var var5: Double? @AppStorage("var6") private var var6 = 0.0 @AppStorage("var7") private var var7 = 0.0 @AppStorage("var8") private var var8: String? @AppStorage("var9") private var var9: Data? @AppStorage("var10") private var var10 = true @AppStorage("var11") private var var11 = 0 var body: some View { Toggle("Var 1", isOn: $var1) ... } }
Jun ’24
Reply to NSProgressIndicator bindings don't do anything
But according to Progress documentation:: Each of the properties of a progress object, including totalUnitCount, completedUnitCount, and fractionCompleted, support key-value observing (KVO). This makes it extremely easy for a view or window controller object to observe the properties, and update UI elements, such as progress indicators, when the values change.
Jun ’24
Reply to iPad Pro 13" screenshots for the App Store
The App Store Connect API documentation still doesn't list the new iPads: https://developer.apple.com/documentation/appstoreconnectapi/screenshotdisplaytype When adding screenshots to 13" iPads on the website, they still seem to use the display type APP_IPAD_PRO_3GEN_129 when listed by the API, and uploading to that same type uploads them to the 13" display type instead, and then there is the requirement that one still has to upload screenshots for 12.9" display type, without an apparent way of doing so. I would expect to have an option to upload to 13" display type that is also used for 12.9" display type as well.
May ’24
Reply to URL.checkResourceIsReachable() throws error if file is on FTP server and name contains special characters
FTP is fundamentally broken at the protocol level. You won’t be able to make non-ASCII file names work with FTP in the general case. Thanks for your comments. Regarding your link "On FTP", I was wondering about this: FTPS is FTP over TLS (aka SSL). While FTPS adds security to the protocol, which is very important, it still inherits many of FTP’s other problems. Personally I try to avoid this protocol. in particular the part "it still inherits many of FTP’s other problems". What are these other problems? At the beginning of the post you only mentioned privacy and security, but these are already fixed with FTPS according to you. Also do you have any clue why open(source.path, O_RDONLY) returns a valid file descriptor if source is a directory and if it's a regular file it returns -1 (see my previous post)?
Apr ’24