We can call an instance method without referring and using a dot syntax on that instance in Swift, which is very interesting to study. The trick is taking out the signature of that instance method, and then passing the instance you want to call method on.

Say we have a class and a method like this:

class MyClass {
    func method(number: Int) -> Int {
        return number + 1
    }
}

To call the method, the normal way to do so is creating an instance of MyClass, then use .method() on it:

let object = MyClass()
let result = object.method(1)

// result = 2

This limits us to decide the object and its method calling on compile time. In fact by the way mentioned above, we can rewrite the code above to:

let f = MyClass.method
let object = MyClass()
let result = f(object)(1)

It might seem weird at first time, until you know the syntax here. In Swift, Type.instanceMethod can be used to get a currying method. If we inspect the type of f, we could find it:

f: MyClass -> (Int) -> Int

For the kind of statement like Type.instanceMethod, in fact this code:

let f = MyClass.method

is equivalent as this kind of closure assignment:

let f = { (obj: MyClass) in obj.method }

Now you can tell why the code above can be compiled and run correctly.

This code is only for an instance method. You cannot use this trick in neither class method nor the getter or setter of a property. As an extreme case, if the we have a class method and an instance method sharing the same name:

class MyClass {
    func method(number: Int) -> Int {
        return number + 1
    }

    class func method(number: Int) -> Int {
        return number
    }
}

MyClass.method will refer to the class method. If we want to take the instance method, we have to explicitly point it out in the type declaration. This could not be only used here, but also other name ambiguous situations. We will see more example about it later.

let f1 = MyClass.method
// class func method

let f2: Int -> Int = MyClass.method
// same as f1

let f3: MyClass -> Int -> Int = MyClass.method
// currying version of instance func method