Retrieved object giving nil property values

I’m trying to retrieve an object from the database and it the object looks like its successfully getting retrieved but when I cast it as the class I need and try to read the properties the properties come up as nil.

I have a very simple price class

class Price: NSObject
{
    var price: Double?
    var activeFlag: Bool?
    
}

and use the following to access that price in Backendless

    var backendless = Backendless.sharedInstance()
    
    func getPrice(completion: (Price?, Fault?) -> Void) {
        
        let query = BackendlessDataQuery()
        
        let dataStore = self.backendless.persistenceService.of(Price.ofClass()) as IDataStore
        dataStore.find(
            query,
            response: { (retrievedCollection) -> Void in
                print("Successfully retrieved: \(retrievedCollection)")
                let collection = retrievedCollection.getCurrentPage()
                let priceArray = collection as! [Price]
                for i in priceArray{
                    print(i)
print(i.price)


                    print(i.activeFlag)
                }
                if carArray.count == 1 {
                    completion(carArray[0], nil)
                } else {
                    print("Error")
                }
            },
            error: { ( fault: Fault!) -> Void in
                print("Error: \(fault)")
                
        })
    }

In my first print statement(“print(i)”) I get the following output in my console:
<test.Price: 0x7fe0cc00e9c0>

For the second print statement I get nil

nil

Once I get my collection from Backendless I cast it as an array of Price objects and that seems fine. But the price object doesn’t seem to have any properties, am i missing something?

Hi Chris,

Can you please make a screenshot of your Price table or provide your app ID?

Hi Chris,

You should to fix your class as:

class Price: NSObject
{
var price: Double = 0.0
var activeFlag: Bool = false // or true

}

For Swift data objects, the Bool, Int, Double and Float types must not be declared optional. Please, see this doc.

Regards,
Slava