Reputation: 69
Hello I have a problem with Swift Protocol
I have declared a protocol named BaseViewModel
I have class called AViewModel and BViewModel which conform to protocol BaseViewModel
class AViewModel : NSObject , BaseViewModel
class BViewModel : NSObject , BaseViewModel
Now , I need to declare a completion block that returning those Object which conform to protocol BaseViewModel
typealias ViewModelCompletionBlock = (_ value : BaseViewModel) -> Void
In objective-C I used to declare something like this
id<BaseViewModel>
In Swift, how to declare the same ??
Upvotes: 0
Views: 87
Reputation: 4236
Do you mean something like this?
typealias ViewModelCompletionBlock<T: BaseViewModel> = (_ value : T) -> Void
Upvotes: 1