I agree with the comments above that it is not possible to write an extension like this, but wanted to suggest using a global function instead, with the option of currying it for greater flexibility.
For some background information, see this blog post by Ole Begemann where he notes that in Swift,
Instance methods are just curried functions that take the instance as the first argument.
So from Swift's point of view there is no difference between instance.function()
and function(instance)()
.
I don't know what you are trying to do, but a global function that looks like this...
func skTextureFunc(textures: [SKTexture])(arg: SomeArgType) { }
...is, for all intents and purposes, exactly the same as an instance method that can be bound to a particular instance of [SKTexture]
.
And if you want, you can partially apply the function to a specific instance of [SKTexture]
that you will be using repeatedly and then use it as if it were an instance method bound to that instance. So, for example:
class Example {
var localSKTextureFunc: SomeArgType -> () {
return skTextureFunc(textureArray)
}
let textureArray = [SKTexture]()
}
So globally you can always use the curried function, and locally (inside a class) you can bind the curried function to a specific instance of a class.
I know that's not exactly what you asked, but I think it is the best work around for the fact that we can't write extensions like the one you describe.