在Swift类中访问协议属性 [英] Accessing protocol property in Swift class
本文介绍了在Swift类中访问协议属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用协议将数组从一个类传递到另一个类。
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
就像这样:
delegate.dataArray
它说实例成员'dataArray'不能用于PinArray类型
It says that "instance member 'dataArray' cannot be used on type PinArray"
那我该怎么办?
推荐答案
我用错字声明了委托,应该是这样的:
I declared the delegate with a typo, it should be like this:
var delegate: PinsArray?
这篇关于在Swift类中访问协议属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文