Restrictions
suggest changeA where clause can restrict a method on a generic type. Swift 2 spelled this constraint StringLiteralConvertible and used uppercaseString. The body only works for String, and Swift 3 and later use uppercased().
extension Array where Element == String {
func toUpperCase() -> [String] {
var result = [String]()
for value in self {
result.append(value.uppercased())
}
return result
}
}
Example of use
let array = ["a","b","c"]
let resultado = array.toUpperCase()
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents