Post

Replies

Boosts

Views

Activity

Reply to Date.FormatStyle.Symbol.Hour defaultDigits shows leading zero if amPM is set to .omitted
This is absolutely a bug in Foundation. The documentation and examples both say that the leading "0" shouldn't be included. Until the bug is fixes, the solutions available would be to either do string manipulation or to use a different format style. Each one has their own drawbacks when it comes to internationalization, so deciding which solution to use is a matter of weighing your needs against the drawbacks. 1. Trim Characters Simply check for the existence of a leading 0 character, and remove it if needed. // https://www.hackingwithswift.com/example-code/strings/how-to-remove-a-prefix-from-a-string extension String { func deletingPrefix(_ prefix: String) -> String { guard self.hasPrefix(prefix) else { return self } return String(self.dropFirst(prefix.count)) } } let testDate = try! Date("2024-01-01T10:36:01Z", strategy: .iso8601) let dateString = testDate.formatted(.dateTime.hour(.defaultDigits(amPM: .omitted)).minute()) // 03:36 dateString.deletingPrefix("0") // 3:36 This would only work for locales that use Arabic numerals of course. If you're relying on strict internationalization then you would need to be a bit more clever in detecting leading characters. 2: Date.VerbatimFormatStyle This would let you build out a fully custom date string, but at the cost of having the hour minute separator be hardcoded to be a colon character. let testDate = try! Date("2024-01-01T10:36:01Z", strategy: .iso8601) let hourMinuteStyle = Date.VerbatimFormatStyle( format: "\(hour: .defaultDigits(clock: .twelveHour, hourCycle: .zeroBased)):\(minute: .defaultDigits)", timeZone: .autoupdatingCurrent, calendar: .autoupdatingCurrent ) testDate.formatted(hourMinuteStyle) // 3:36 // OR testDate.formatted( .verbatim( "\(hour: .defaultDigits(clock: .twelveHour, hourCycle: .zeroBased)):\(minute: .defaultDigits)", timeZone: .autoupdatingCurrent, calendar: .autoupdatingCurrent ) )
Aug ’24
Reply to "Selects Code Structure" not visible in Xcode Settings > Navigation
I was also struggling with this! I was convinced that I had done something to my Xcode 15 install which caused this option to disappear, but it turns out that this is just a big change that was made in Xcode 15: The Show Code Actions command has been replaced with Show Quick Actions to quickly access any menu command. By default, Command-clicking a token in the editor now performs Jump to Definition. This can be changed in the Navigation preferences. Control-clicking a token brings up the standard contextual menu that now contains all the commands that were available in the Code Actions. (86179596) Xcode 15 Release Notes: New Features Apple wants you to either use the new ⌘+Shift+A keyboard shortcut to access these options, or to just right click and access them there.
Jan ’24