swift - weak cannot be applied to non-class type uiimageview -


i have class in swift needs have weak pointer array of objects allocated in class. have

class myview: uiview {     var lines:[cashapelayer] = []     weak var avatars : [uiimageview]? 

the error is

'weak' cannot applied non-class type '[uiimageview]'

i tried no avail:

weak var avatars : [uiimageview?]? 

weak cannot applied non-class type:

it means can’t have weak reference value type instance(e.g. array, dictionary, string, etc…) because these struct not class. give weak reference of class-type(e.g uiimage, uiimageview, etc…).in case, trying give weak reference uiimageview array , know array value type, 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 have protocol of struct type:

protocol someprotocol{     func dosomething()   } 

we cannot declare variables of type weak:

weak var delegate: someprotocol? //compiletime error(wrong) 

but if make protocol of class type this:

protocol someprotocol: class{     func dosomething() } 

we can declare variables of type weak:

weak var delegate: someprotocol? //correct 

i think understand it, why happens in protocol?

same reason: give weak reference of class-type


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -