Swift Language Restrictions


Example

It is possible to write a method on a generic type that is more restrictive using where sentence.

extension Array where Element: StringLiteralConvertible {
  func toUpperCase() -> [String] {
      var result = [String]()
      for value in self {
          result.append(String(value).uppercaseString)
      }
      return result
    }        
}

Example of use

let array = ["a","b","c"]
let resultado = array.toUpperCase()