Weak Cannot be applied to non-class type:
It means you can’t have a weak reference to any value type instance(e.g. Array, Dictionary, String, etc…) because these all are struct not class. You only give weak reference which are of class-type(e.g UIImage, UIImageView, etc…).In this case, you are trying to give weak reference to UIImageView Array and we know array is a value type, so it is not possible.
For example:
weak var str: String? //CompileTime Error(Wrong)
weak var arr: Array? //CompileTime Error(Wrong)
weak var imageView: UIImageView? //Correct
In case of Protocol:
If we have just a protocol of struct type:
protocol SomeProtocol{
func doSomething()
}
We cannot declare variables of this type as weak:
weak var delegate: SomeProtocol? //CompileTime Error(Wrong)
But if we make protocol of class type like this:
protocol SomeProtocol: class{
func doSomething()
}
We can declare variables of this type as weak:
weak var delegate: SomeProtocol? //Correct
I think you easily understand it, why this happens in protocol?
Same reason: You only give weak reference which are of class-type