user103412
user103412

Reputation: 25

restriction on properties of Realm Model

I have this model

#import <Realm/Realm.h>

@interface RGGoal : RLMObject

@property NSString *title;
@property NSNumber *totalTime;
@property NSNumber *noMileStones;
@property NSString *goalDescription;

I setup breaking points and figured that when RLMRealm *realm = [RLMRealm defaultRealm]; is called the app terminates with following

'RLMException' exception: Property of type NSNumber must descend from RLMObject

Does anyone now how to get around this problem?

Upvotes: 0

Views: 2100

Answers (2)

Dongjin Suh
Dongjin Suh

Reputation: 458

Since version 0.96.0, optional numbers can be stored using an NSNumber * property which is tagged with the type of the number. You can use NSNumber *, NSNumber *, NSNumber *, and NSNumber *.

Please check https://realm.io/news/realm-objc-swift-0.96.0/

Upvotes: 1

geisshirt
geisshirt

Reputation: 2497

The problem is that you're using NSNumber as type for your properties. Realm doesn't support that as NSNumber can be any numeric value (bool, integer, double, etc.). You must use types like int, float, double, etc. Please take a look at http://realm.io/docs/cocoa/0.81.0/api/Classes/RLMObject.html.

Upvotes: 5

Related Questions