Answer by Cykelero for Getting path to users Library folder in OS X
In Swift, you can also get this path as a URL directly:let currentUserHomeDirectoryURL = URL.homeDirectorylet janeHomeDirectoryURL = URL.homeDirectory(forUser: "jane")
View ArticleComment by Cykelero on filter:blur() is causing glitching in Safari
This also seems to fix the performance issue that occurs when translating an element that's got a filter: blur applied.
View ArticleComment by Cykelero on xcodebuild print errors only
This still outputs “note:” lines, annoyingly, but is already massively quieter than the default.
View ArticleComment by Cykelero on Why is async task cancelled in a refreshable Modifier...
Yeah, there's potential for that task to incorrectly update state when it shouldn't. (e.g. you trigger a refresh of a list, then the list's data source changes; the refresh finishes, and populates the...
View ArticleComment by Cykelero on SwiftUI Fetching data cancelled when refreshing a task
This question is similar to: Why is async task cancelled in a refreshable Modifier on a ScrollView (iOS 16). If you believe it’s different, please [edit] the question, make it clear how it’s different...
View ArticleAnswer by Cykelero for Convert String.Index to Int or Range to NSRange
You can directly convert between an Objective-C style integer offset, and a Swift string index:// Offset to indexlet string = "Test"let offset = 2let index = String.Index(utf16Offset: offset, in:...
View ArticleAnswer by Cykelero for How do I check if the shift key is currently being...
Look in NSEvent.modifierFlags:let shiftIsPressed = NSEvent.modifierFlags.contains(.shift)
View ArticleAnswer by Cykelero for macOS Mojave: Change app icon to match Dark/Light Mode
It seems like your best bet is to handle the icon change yourself: listen to appearance change notifications, and update the icon accordingly.To set the Dock icon:The easiest way is to assign a NSImage...
View ArticleAnswer by Cykelero for What is the difference between a spindump and a...
(This answer is based on limited personal experience: it's probably very incomplete)A spindump seems to contain much more information than a sample:A sample contains thread stack traces for the threads...
View ArticleAnswer by Cykelero for Swift Codable struct recursively containing itself as...
Here's Sweeper's Box class, reworked as a property wrapper, to make it even nicer to use:@propertyWrapperclass Boxed<Wrapped: Codable> { var wrappedValue: Wrapped init(wrappedValue: Wrapped) {...
View ArticleAnswer by Cykelero for In AutoLayout can you combine both horizontal and...
Riffing off of Shehata's answer, with different code formatting:NSLayoutConstraint.activate( ["H:|-0-[view]-0-|","V:|-0-[view]-0-|" ].flatMap { NSLayoutConstraint.constraints( withVisualFormat: $0,...
View ArticleAnswer by Cykelero for Why is accessing CustomStringConvertible’s description...
As a hint, a previous version of that same piece of documentation reads:Note: String(instance) will work for an instance of any type, returning its description if the instance happens to be...
View ArticleAnswer by Cykelero for How can I preview a Gist in GitHub?
As of November 2021, there is a preview tab when editing a Markdown Gist.The Gist's file extension has to be set to .md for the tab to be displayed.
View ArticleAnswer by Cykelero for Is there a way to view the undo stack?
You can print your undo manager's _undoStack private property:let undoStack = object_getIvar(undoManager, class_getInstanceVariable(UndoManager.self,...
View ArticleHow to hide the letters on a .numberPad keyboard?
By default, when using a .numberPad keyboard on iPhone, the number keys also feature letters at the bottom of each key.The letters are purely cosmetic, to help people with number input; but in my case...
View ArticleAnswer by Cykelero for tableView.selectRow has no effect when called within a...
In the specific case of a delete action, you can implement the tableView(tableView: cell: indexPath:) delegate method, and perform the selection there; make sure to check that the cell didn't simply...
View ArticletableView.selectRow has no effect when called within a UIContextualAction...
When calling selectRow(at:animated:scrollPosition:) inside a UIContextualAction callback, nothing changes: the specified row doesn't turn gray.Here's the simplest code I could write that exhibits the...
View ArticleAnswer by Cykelero for tableView.selectRow has no effect when called within a...
One makeshift way to have the selection operation succeed is to use a timer, in order to call selectRow() after the deletion animation is finished:override func tableView(_ tableView: UITableView,...
View ArticleComment by Cykelero on cocoa + context sensitive menu on NSTableView with...
In a nutshell: assign a delegate to your NSMenu, and implement a delegate method such as menuNeedsUpdate(_:). It'll allow you to set the menu's items to whatever you'd like, anytime the menu is shown....
View ArticleComment by Cykelero on Safari iPhone - How to detect zoom level and offset?
This seems to work, in macOS Safari, for computing the amount of Page Zoom (i.e. zooming in and out with ⌘+ and ⌘-). However, it seems to always return 1 in Firefox.
View Article