Mapped data classes do not work with Boolean fields

I have a table with a Boolean column. When I use a mapped class to this data type in Swift, with Bool? fields, they are always nil regardless of the column value in the cloud.

If I use NSNumber? datatypes in the Swift code they work.

Do Bool? not work in Swift ?

Hi Ian,

I just tried and was able to reproduce the error. I am scheduling a “blocker” ticket which will be fixed asap.

Regards,
Mark

Hi Ian,

The properties of Integer, Floating and Boolean type MUST be initialized, they MAY NOT be Optional (?):

class Comment: NSObject
{
var objectId: String?
var message: String?
var isPublished: Bool = false
}

class OrderItem : NSObject {

var ownerId : String?
var itemName : String?
var price : Double = 0.0
var quantity = 0;
var byCredit: Bool = false

}

Regards,
Slava

But Boolean columns can be null in the database, so shouldn’t they be nullable on the client too. Are you saying that you can’t use nullable Boolean columns. I have been using them in Parse as a trip state, where null means something different from both true and false.

Using NSNumber? works fine in this case?

Yes it does but makes the code “in clean”. It becomes misleading and is just asking for bugs if it’s a Bool? Then that’s what should be used.

We will investigate this problem asap, but now you should use initialized numeric OR NSNumber? - it is your choice

Ian,

The current requirement is not the final solution, it is more of a temporary workaround due to how we perform reflection on the serialized objects.

Regards,
Mark

Thanks. Just out of interest, How can I track the bug so I know When it’s resolved and can go back and update my code?

If a bug report came through support, we update each ticket with a notification that it is fixed.

Hi Ian,

You shouldn’t use Bool?, Int?, Double?, Float? in your data model classes.
Foundation provides a bridge from Bool to NSNumber (as well as bridges for Int, Double, etc.), but it does not provide a bridge for Bool? , etc. That’s why it is not visible to Objective-C (Backendless SDK is implemented in Objective-C).

So, this is WRONG class:

class WrongNumerics : NSObject {
    var logic : Bool?
    var count : Int?
    var real : Double?
    var afloat : Float?
}

and here is RIGHT class:

class RightNumerics : NSObject {
    var logic : Bool = false
    var count : Int = 0
    var real : Double = 0.0
    var afloat : Float = 0.0
}

Regards,
Slava