Field property switched when saved to backendless, Double truncated

The front end is an iOS app using swift.

I just added 2 new fields to my Order class to store the users current latitude and longitude:

  • userLat
  • userLong

Here is my class definition

class Order: NSObject
{
    var objectId: String?
    var user: BackendlessUser?
    var userLat: Double = 0.0
    var userLong: Double = 0.0
    var price: Double = 0.0
    var paymentProcessingStatus = "Unprocessed"
    
    
    override init()
    {
        super.init()
    }
    
    init(user: BackendlessUser)
    {
        super.init()
        self.user = user
    }
    
}

I set the userLat/userLong values using CLLocation lat/long then save the object to backendless with following:

func createOrder(order: Order, completion: (Order?,Fault?) -> Void)
    {
        let dataStore = backendless.data.of(Order.ofClass())


        print(order.userLat)
        
        dataStore.save(
            order,
            response: { (result: AnyObject!) -> Void in
                print("Create order response received")
                let savedOrder = result as! Order
                print("Order saved: \(savedOrder.user!.email)")
                completion (savedOrder, nil)
            },
            error: { (error: Fault!) -> Void in
                print("server reported error: \(error)")
                completion(nil, error)
        })
    }

When I print userLat at line 5 I get the correct value for userLat, but when I check the value in Backendless the userLat and userLong values are switched. This is very strange to me as obviously there’s no way my code has transformed the values since the asynch save call occurs immediatley after printing the value so the order object I sent to backendless must have the correct userLat value.

At first my only problem was the switched values. I tried going into the backendless schema editor and removing the userLat/userLong columns in case something weird had occurred when they were created then tried to save a new order. I now still have the switched values problem but theres an additional problem. My userLat value is now getting truncated at before the decimal point. I had a similar problem with Backendless truncating Double values before: http://support.backendless.com/t/double-value-is-being-rounded-to-nearest-value

In the previous case I was advised to switch the data type to int then back to double. Last time that didn’t work so I simply created a new app in backendless and started using that which fixed my problem. I tried it again this time and no luck, the updated data type doesn’t even save.

I attached a screenshot of the problem fields, as you can clearly see the userLat has 14 digits after the decimal point, whereas the userLong has none. Those two fields should look the same, and again for some reason those two values are being switched.

Screenshot 2017-01-31 22.20.19.png

I guess I fixed it, strange solution though…

I deleted the 2 columns again (userLat/userLong) and manually created the columns in Backendless and that fixed both my problems.

Any idea why I had a problem when creating the properties through the API? This is in my dev environment and I’m nervous to move it to production given the erratic behavior. Would like to understand why I had the problem. (see screenshot which looks identical to original)

Screenshot 2017-01-31 22.37.46.png

Thanks for the update. Just to clarify, did the problem occur only when the columns were created automatically by Backendless?

Yeah, the problem only happened when the columns were created automatically by backendless in response to an API call from my app which included new properties for my order object.