Hi,
I have an Student entity class that stores a boolean parameter called ‘active’. However, when saving the model to the backend, the parameter always gets stored as NULL when I hardcode it to TRUE.
Disclaimer regarding my code, I’m new to Swift…
class Student : BackendlessEntity {
var firstName: String?
var middleName: String?
var lastName: String?
var active: Bool?
}
The save action method looks like this: @IBAction func saveForm(sender: AnyObject) {
let student = Student()
let backendless = Backendless.sharedInstance()
backendless.persistenceService.of(Student.ofClass()).save(student, response: { (resondse) -> Void in
self.navigationController?.popViewControllerAnimated(true)
}) { (error: Fault!) -> Void in
// There was a problem, check error.description
print(“Error: (error) (error.description)”)
}
}
The result for activity when saving is done is always NULL. Am I doing something wrong here?
I came across same issue, and found out that the optional “Bool?” was causing the issue. By changing type to “Bool” resolved the issue for me. However, I’m sure there are cases where you wish to handle nil data case hence I also used optional data type in beginning…
<below does not work>
class BooleanTest: BackendlessEntity {
var boolVal: Bool?
override init() {
boolVal = true
super.init()
}
}
<This works as expected>
class BooleanTest: BackendlessEntity {
var boolVal: Bool
I have a similar problem. I am unable to save an object and the error message lists the four Swift Bool properties:
Unable to save object - invalid data type for properties - attendingComplete, minimallyInvasive, redo, viewedByResident. You can change the property type in developer console.
Here is my class:
class Case: NSObject{
static let sharedInstance = Case()
var objectId = ""
var created: NSDate?
var updated: NSDate?
var caseDate: NSDate?
var caseOfDay: Int
var procedureType = ""
var procedureDetail = ""
var redo: Bool
var minimallyInvasive: Bool
var residentZwischStage = ""
var residentDifficulty = ""
var attendingZwischStage = ""
var attendingDifficulty = ""
var attendingComments = ""
var attendingComplete: Bool
var attendingObject: AllowedUsers?
var institutionObject: Institution?
var residentObject: AllowedUsers?
var viewedByResident: Bool
var caseDateSummary = ""
override init() {
redo = false
minimallyInvasive = false
attendingComplete = false
viewedByResident = false
caseOfDay = 1
super.init()
}
I am going to make a simpler case. Here is a class called TestTable:
import Foundation
class TestTable: NSObject {
var field1 = ""
var field2: Int
var field3: Bool
override init() {
field2 = 1
field3 = false
super.init()
}
}
Here is the method body to save:
let t = TestTable()
t.field1 = “Hello”
t.field3 = true
let datastore = Backendless.sharedInstance().data.of(TestTable.ofClass())
datastore.save(t, response: { (result: AnyObject!) -> Void in
print(“saved”)
}) { (fault: Fault!) -> Void in
print(fault.message)
}
Here is the fault message:
Unable to save object - invalid data type for properties - field3. You can change the property type in developer console.
If I remove the Bool field, everything saves just fine
The true schema is shown when you click the “Table Schema and Permissions” button, although one can see the data types here as well. Could you email your app id and ios secret key to support@backendless.com? I’d like to run my app against your backend.
Worked just fine - you should see an object saved in the TestTable table.
Try updating the backendless library. Alternatively, try creating a project from scratch, follow the instructions from here and see the minimal code works.
You were able to create a Bool field. But when I created the table de novo, although my field3 is a Bool in my class, the field3 column is an Int in the Backendless console. Image attached. I have re-downloaded all of your files and still get the same result. Remember this is Swift 2.x. Could there be an issue in the datatype mapping from objC to swift?http://support.backendless.com/public/attachments/b0efe9b1436f5e01ef691ace0d51e835.png</img>
Just to confirm: we run exactly the same code, against the same backend, only in your case Backendless declares field3 as int and in mine it is Boolean?
I’m still trying to resolve my Swift Bool save issue. I made a new app to save a Bool in one field and an Integer in another field. I downloaded a fresh copy of your iOS SDK. On the simulator, I get an invalid data type for properties error when I try to save to a Boolean field. I tried this on a different Mac and got the same error. Running the program on an actual iPhone with iOS 9.2, the Bool saves without error. When I run it on an actual phone running iOS 8.2 I get the invalid data type error. Does this allow you to have any more insights into the problem?