Reference method from different class as curried function

390 views Asked by At

There are two merge methods in RACSignal:

- (RACSignal *)merge:(RACSignal *)signal;
+ (RACSignal *)merge:(id<NSFastEnumeration>)signals;

When I write RACSignal.merge it references static method:

class func merge(signals: NSFastEnumeration!) -> RACSignal!

How to reference object method? I can't write self.merge, because it is in wrapper class and self is not RACSignal.

2

There are 2 answers

0
iHunter On BEST ANSWER

As methods in Swift are curried class functions, compiler has to decide which overload to choose.

To reference instance's merge method you need to specify it's exact type:

let instanceMerge: RACSignal -> RACSignal! -> RACSignal! = RACSignal.merge

0
Martin R On

The curried class function and the curried instance function have different signatures. Similarly as in

you can refer to each by specifying the signature explicitly.

I have no experience with RACSignal, so here is an artificial example that hopefully can be applied in your case:

class MyClass {
    class func foo(s : String) {
        println("class foo: \(s)")
    }
    func foo(s : String) {
        println("instance foo: \(s)")
    }
}

// Reference to the class method:
let f1 : String -> Void = MyClass.foo

// Call the class method:
f1("bar")
// Output: class foo: bar

// Reference to the instance method:
let f2 : MyClass -> String -> Void = MyClass.foo

// Call the instance method:
let obj = MyClass()
f2(obj)("bar")
// Output: instance foo: bar