0
votes

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 ??

1
What is the problem with your typealias ViewModelCompletionBlock = (_ value : BaseViewModel) -> Void ? That already looks correct.Martin R
Can you make as best if my answer helped you?Rico Crescenzio

1 Answers

1
votes

Do you mean something like this?

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