mapTableToClass in Backendless 4 Swift 3

I need help

Does not work for me

MyProject

  1. AppDelegate.swift
let backendless = Backendless.sharedInstance()!




@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

    let APPLICATION_ID = "EDE47485-C45D-2F41-FF0C-043337FCCA00"

    let API_KEY = "****-****-****-****-****"







    

    var window: UIWindow?







    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        // Override point for customization after application launch.

backendless.initApp(APPLICATION_ID, apiKey: API_KEY)

//backendless.persistenceService.mapTable(toClass: "Users", type: MyUser.ofClass())

        backendless.data.mapTable(toClass: "Users", type: MyUser.ofClass())

//backendless.persistenceService.mapTable(toClass: "Questions", type: MyQuestions.ofClass())

        backendless.data.mapTable(toClass: "Questions", type: MyQuestions.ofClass())

        return true

    }






  1. MyUser.swift

import Foundation
class MyUser: NSObject {
    var name: String?
     var location: String?
     var gender: String?
}






  1. MyQuestions.swift
import Foundation
class MyQuestions: NSObject {
    var question: String?

}


  1. MainViewController.swift

import UIKit
class MainViewController: UIViewController {
    
 let myUser = MyUser()
let myQuestion = MyQuestions()
    override func viewDidLoad() {
        
        super.viewDidLoad()

        
        if let gender = myUser.gender {
            print(gender)
        }
        if let question = myQuestion.question {
            print(question)
        }
...
}

gender and question ALWAYS nil (((
What am I doing wrong?

Hello,

Firstly, what version of iOS-SDK do you use?
Secondly, it’s a bad practice to map the “Users” table to the custom class. Please use the BackendlessUser class instead.
I’ve just checked the issue with nil with the MyQuestions class but everything works fine (iOS-SDK v 4.0.6)

class MyQuestions: NSObject {
 var question: String?
}
func mapAndGetData() {
 backendless.data.mapTable(toClass: "Questions", type: MyQuestions.ofClass())
 let dataStore = backendless.data.of(MyQuestions.ofClass())
 let questions = dataStore?.find() as! [MyQuestions]
 for q in questions {
 print(q.question!)
 }
}

Regards, Olga

thanks for the answer.
iOS-SDK v 4.0.6 (via pod)

I’m new, maybe I’m doing something wrong.
Please send your project.
I will compare with my own.

We do not offer ready-made projects. Please, take a closer look at the code example that Olga wrote, maybe you’ll notice the difference.

Best,
Stanislaw

Thank you.
If I use the example of Olga, then:

print(q.question!)

in console:

MyQuestions

It`s nice.

if I’m creating a class object


let myQuestion = MyQuestions()
print(myQuestion.question)

in console


nil

why?

You’ve created an instance of MyQuestions class but haven’t set the question property’s value.

let myQuestion = MyQuestions()
myQuestion.question = "Test Question?"
print(myQuestion.question)

To retrieve the existing data from Backendless you should run this code:

let dataStore = backendless.data.of(MyQuestions.ofClass())
let questions = dataStore?.find() as! [MyQuestions]
for q in questions {
print(q.question!)
}

Please check this doc.

Regards, Olga


Right.
I want to get data from the database.

For example, in local parse server:


import UIKit
import Parse

 class MyOrders: PFObject, PFSubclassing {
    
    @NSManaged var orderCity: String
    @NSManaged var isVisible: Bool
    @NSManaged var modifiedAt: NSDate
    @NSManaged var servicePrice: [[String]]
    @NSManaged var orderDescription: String
    @NSManaged var atHome: Bool
    @NSManaged var departure: Bool
    @NSManaged var geoPointOrder: PFGeoPoint
    
}



let myOrder = MyOrders()

print(myOrder.isVisible) -> Console.log : true
peint(myOrder.orderDescription) -> Console.log: "my order Description"

I want to do so. Is this possible?

Backendless iOS-SDK is not the same as Parse SDK.
To retrieve data from database:

let dataStore = backendless.data.of(MyQuestions.ofClass())
let questions = dataStore?.find() as! [MyQuestions] // array of Questions
for q in questions {
print(q.question!)
}

Backendless iOS-SDK is not the same as Parse SDK.

Means with Backendless it is impossible to make it.

This is very bad(((
Thank you.

Вы говорите по-русски?

Impossible? Didn’t Olga just show you how to retrieve data??

Pay attention to the code in the previous comment - Backendless can all the same as Parse, and even more. But in another way.
This is an English-language forum. We ask to communicate here exclusively in English so that other our users and customers can understand what we are talking about and find a solution to the existing problem.

Have you read what I’m writing about? It seems, no.

Olga, said true, but the implementation is different in the backendless.

Yes, I have read everything, including Olga’s responses where she showed examples. Of course the implementation is different in Backendless. We’re not interested in copying parse’s implementation and thus provide our own. It is important to read the docs and see the examples we show there. Simply applying what you know about Parse with Backendless will not get you far.

Regards,
Mark

Yes, I agree with you.
I asked. They answered me.
Pars is not equal to the backendless.
He’s different.

The problem is solved!
Thanks to all!