I am trying to use a protocol to pass an array from one class to another.
protocol PinsArray {
var dataArray: [LocationPost] {get set}
}
When I am trying to create a delegate in class, which should receive it does not work. I cannot access the property
var delegate = PinsArray.self
Like this:
delegate.dataArray
It says that "instance member 'dataArray' cannot be used on type PinArray"
So what do I do wrong?
You are assigning the type of
PinsArray
todelegate
instead of assigning an instance of a class that conformsPinsArray
. You would need to implement an a class that conforms toPinsArray
and assign an instance of that class to delegate. See the following example:You would use the class above to create an instance of an object that conforms to
PinsArray
.Then you could use:
I declared the delegate with a typo, it should be like this: