ddwdwwf drewret
ddwdwwf drewret

Reputation: 69

Swift Protocol How to declare as Generic conformance

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

Answers (1)

Rico Crescenzio
Rico Crescenzio

Reputation: 4236

Do you mean something like this?

typealias ViewModelCompletionBlock<T: BaseViewModel> = (_ value : T) -> Void

Upvotes: 1

Related Questions