Error saving data to a new table

Are you looking for help?

This is a support forum for reporting issues related to Backendless services. Please note that due to our support policy we cannot provide you help with debugging your code, consulting in regards to any language or third-party library usage. For this kind of questions we recommend using more appropriate forums like Stack Overflow.

In order to suggest you a quality solution, we shall usually ask you to provide the details mentioned below first. Including them into your topic right away helps us to start investigating your issue much faster.

In case you have a suggestion or an idea, the details below are not always required, though still any additional background is welcome.

Backendless Version (3.x / 5.x, Online / Managed / Pro )

5.x, Online

Client SDK (REST / Android / Objective-C / Swift / JS )

Swift

Application ID

StudentActivities

Expected Behavior

Please describe the expected behavior of the issue, starting from the first action.

  1. The app runs.
  2. It tries to save new objects from its [SAEventBE] array
  3. A new table named “SAEventBE” is created in Backendless with the data

Actual Behavior

Please provide a description of what actually happens, working from the same starting point.

Be descriptive: “it doesn’t work” does not describe what the behavior actually is – instead, say “the request returns a 400 error with message XXX”. Copy and paste your logs, and include any URLs.

  1. The app runs and the saving code runs
  2. No new table is created in the Data section
  3. No items are saved.

I am curious as to why this is happening. When I replace this class with a simpler class, the table saves fine and is created correctly in Backendless. So there must be something about this class that makes it not save. Any ideas? I don’t see any obvious error messages but I’m not really sure what to look for.

Help please – this message is on behalf of one of my students but she hasn’t been able to figure out the problem and I haven’t either!

Hi Roger,

Could you please either attach or post inline the class which you’re having trouble with?

Regards,
Mark

Sure, here it is:

import Foundation
@objcMembers
class SAEventBE: NSObject, Codable {
var eventID: Int = 0
var totalLikes: Int = 0
var objectId: String?

override init() {
    
}

}

Thanks. I wonder if the Codable reference has anything to do with the problem. Have you tried without it?

I don’t think that’s the issue – when we tried a simple example in class to demonstrate how Backendless worked, we used a class that also implements Codable and it worked just fine. I used the credentials for this Backendless project in that app and the object array was written successfully. There must be something about this app that isn’t working, but I can’t figure out what because the saving code is exactly the same:

    let writeStore = backendless.data.of(SAEventBE.ofClass())
    Types.tryblock({() -> Void in
        for event in self.mySAEventsBE {
            _ = writeStore?.save(event) as Any
        }
    },
                   catchblock: { (exception) -> Void in
                    print("Server reported an error: \(String(describing: exception))")
    })

Feeling very confused…

One more piece of information – when I tried to force-unwrap the writeStore variable I found that it was nil – why would that happen in this case? What about the first line in this code would cause the code on the right side of the assignment operator to return nil?

Hello Roger,
In order to investigate your problem, we need a reproducing sample to work with. If you take the class you provided and only the sample snippet above, does the problem occur? If it does, could you then pack this small project into an archive and attach it here, so that we could run it and get the behavior you describe as well?