Nika Kirkitadze
Nika Kirkitadze

Reputation: 59

typealias generic function variable

I have following function declaration inside class A

typealias Callback<T> = (Result<T>) -> ()

Trying to declare variable in class B

var callbackVariable: A.Callback<T>?

Compiler says: Use of undeclared type 'T'

How to declare variable inside B class?

Upvotes: 0

Views: 72

Answers (1)

Rengers
Rengers

Reputation: 15218

You need to either:

  1. Specify a type for T
  2. Or, make the B class generic as well.
// 1. Specify a type for T
class B {
  var callbackVariable: A.Callback<String>? // Or some other type
}

// 2. Or, make the B class generic as well.
class B<T> {
  var callbackVariable: A.Callback<T>?
}

Upvotes: 2

Related Questions