NNikN
NNikN

Reputation: 3856

Use TypeAlias in other class

I want to use alias defined in the Class1 class . I want to use it into Class2

import UIKit

class Class1: NSObject {
    typealias tp = () -> Void 


}


import UIKit

class Class2: NSObject {    
    func pingTest(){
        var test:tp?
    }
}

Class2 throws compile time error at var test:tp?

Also, the autocompletion does not work. Screen the shot attached with this email. I tried the following thing but that didn't work for me (XCode 6 isn't autocompleting in swift).

enter image description here

Upvotes: 2

Views: 1523

Answers (1)

Sohel L.
Sohel L.

Reputation: 9540

You need to define the TypeAlias as public and that too outside the class.

The other option is to define protocol and inherit to any class.

Upvotes: 5

Related Questions