lcolli71
lcolli71

Reputation: 13

"Cannot find 'RealmProperty' in scope" when trying to use optional double, Swift

I'm using Realm Sync to store data for my iOS app, coded in Swift. I wanted to create an optional double property (budget) for a Realm object (User_budgets). I created the object in the Realm schema and then copied in the Data model SDK that Realm produces which is as below:

import Foundation
import RealmSwift

class User_budgets: EmbeddedObject {
    let budget = RealmProperty<Double>()
    @objc dynamic var date: Date? = nil
}

I then get the error: "Cannot find 'RealmProperty' in scope". I tried changing the code to the below:

@objc dynamic var budget: Double? = nil

But then I get the error: "Property cannot be marked @objc because its type cannot be represented in Objective-C"

I've had a search but can't seem to find anyone who's had this issue before. There's an easy work around, which is simply to make the budget property required (non-optional), but it would be good to know how to be able to create optional double properties in the future. Can anyone help me out?

Upvotes: 0

Views: 2921

Answers (1)

Jay
Jay

Reputation: 35648

I believe you're using the wrong definition for that optional as it's only available in beta 10.8.0-beta.0:

What you have is

let budget = RealmProperty<Double>()

and for all other releases it should be

let budget = RealmOptional<Double>()

See RealmProperty and RealmOptional

oh and here's a link to all of the Support Property Types

Upvotes: 1

Related Questions