You still haven't used precedents, despite the many requests in the comments, so it's hard for you to understand what you need. But, as I said in the comment (and Rob said in response), you wonโt get it literally; extensions do not work this way (at the moment).
As I said in a comment, what I would do is wrap an array in a structure. Now the structure protects and guarantees the type of the string, and we have encapsulation. Here is an example, although, of course, you must remember that you did not indicate what you really would like to do, so this may not be entirely satisfactory:
struct StringArrayWrapper : Printable { private var arr : [String] var description : String { return self.arr.description } init(_ arr:[String]) { self.arr = arr } mutating func upcase() { self.arr = self.arr.map {$0.uppercaseString} } }
And here's what to call it:
let pepboys = ["Manny", "Moe", "Jack"] var saw = StringArrayWrapper(pepboys) saw.upcase() println(saw)
Thus, we effectively isolated our array of strings in a world where we can arm it with functions that apply only to string arrays. If pepboys
were not a string array, we could not wrap it in a StringArrayWrapper to begin with.
source share