I start by saying that I read all the documentation is that I do not want to steal your time.
I’m having some problems with “populate a table view”. I think so I’m just wrong but I can not figure out where. Here is my code.
class DiscoverTableViewController: UITableViewController {
var backendless = Backendless.sharedInstance()
var contacts = []
override func viewDidLoad() {
super.viewDidLoad()
fetchingUsersSync()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return contacts.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
let contact: Contact
// Configure the cell...
contact = contacts[indexPath.row] as! Contact
cell.textLabel!.text = contact.name
return cell
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
// you need to implement this method too or you can't swipe to display the actions
}
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// the cells you would like the actions to appear needs to be editable
return true
}
func fetchingUsersSync() {
Types.tryblock({ () -> Void in
let dataStore = self.backendless.persistenceService.of(Contact.ofClass())
let users = dataStore.find()
let currentPage = users.getCurrentPage()
print("Loaded \(currentPage.count) user objects")
print("Total users in the Backendless starage - \(users.totalObjects)")
for contacts in currentPage as! [Contact] {
print("user name = \(contacts.name)")
}
},
catchblock: { (exception) -> Void in
print("Server reported an error (SYNC): \(exception as! Fault)")
}
)
}
and my Contact class
class Contact : NSObject {
var objectId : String?
var name : String?
var url: String?
var phone : String?
var title : String?
}
and my output (I think is correct, but how to populate myTableView with this output)?
Loaded 9 user objects
Total users in the Backendless starage - 9
user name = Optional("mattia")
user name = Optional("mattia")
user name = Optional("Stefania ")
user name = Optional("Stefania ")
user name = Optional("Stefania ")
user name = Optional("Stefania ")
user name = Optional("Stefania ")
user name = Optional("Mattia")
user name = Optional("Mattia")