Dynamic Advanced Properties in Swift 2.0

I saw this post Advanced Dynamic Properties in Swift , but I don't want it to complete the class in NSObject . This applies to the Realm database. I don't need to have nil properties, but it would be nice if I modeled my database. The Realm documentation, which can be found here https://realm.io/docs/swift/latest/ , says the options are supported. Here is my

The code

 dynamic var complete: Bool? = nil 

and here is mine

Mistake

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

I know this is the same code and error as the message above, but I'm just wondering if the Realm documentation says that it supports it, do they have another job?

+7
ios swift2 optional realm
source share
1 answer

In documents of supported types and additional properties .

String , NSDate , NSData and object properties may be optional. Additional numbers are RealmOptional using RealmOptional .

RealmOptional supports Int , Float , Double , Bool and all versions of Int size ( Int8 , Int16 , Int32 , Int64 )).

Thus, options for String , NSDate , NSData and Object supported with standard fast syntax.

For other numeric types (e.g. Bool ) that are executed using RealmOptional . Then, to use a variable of this type, RealmOptional , you access the value property, which is optional, which represents your base value.

 // definition (defined with let) let complete = RealmOptional<Bool>() // defaults to nil // usage complete.value = false // set non-nil value ... complete.value = nil // set to nil again 
+11
source share

All Articles