Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 2.1: Property cannot be marked dynamic?

How do I fix this compilation error?

dynamic var users = [User]()

Property cannot be marked dynamic because its type cannot be represented in Objective-C

I need dynamic so that certain view controllers can observe (via KVO) users and update their views when users changes.

like image 733
ma11hew28 Avatar asked Jan 21 '26 16:01

ma11hew28


1 Answers

Just as the error mentions

error, not @objc : NSObject:

class A{

}

func something(){
    dynamic var a = [A]()
}

should be changed to:

@objc class A:NSObject{

}

func something(){
    dynamic var a = [A]() //works, all good
}
like image 114
Daniel Krom Avatar answered Jan 24 '26 07:01

Daniel Krom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!