Reputation: 17152
My goal is quiet simple:
2 capitalized letters from a Date()
.
func getWeekday(booking: ClientBooking) {
let formatter = CoreServices.getDateFormatter()
formatter.dateFormat = "EEEEEE"
let weekday = formatter.string(from: booking.date)
print("weekday = \(weekday)")
print("weekday.capitalized = \(weekday.capitalized)")
self.weekdayLabel.text = weekday.capitalized
}
The problem. The 2 print statements result in:
weekday = Fr
weekday.capitalized = Fr
Same does the label.text
. What am I missing? Help is very appreciated.
(Expected of course would be FR
)
Upvotes: 1
Views: 52
Reputation: 385998
From the NSString.capitalized
documentation:
A capitalized string is a string with the first character in each word changed to its corresponding uppercase value, and all remaining characters set to their corresponding lowercase values.
I think you'd be happier with one of these properties mentioned in the “See Also” section of the same page:
var uppercased: String
An uppercase representation of the string.
var localizedUppercase: String
Returns a version of the string with all letters converted to uppercase, taking into account the current locale.
Upvotes: 1