Я сейчас занимаюсь парсером, теперь я как извлекаю данные, но проблема заключается в том, что при попытке сохранить объект в синтаксисе моя первая печать (postsArray) ничего не показывает. вот мой код.parse.com append получение данных
import UIKit
import Parse
class TableViewController: UITableViewController {
var postsArray = [PFObject]()
override func viewDidLoad() {
super.viewDidLoad()
fetchData()
print(postsArray)
tableView.reloadData()
}
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 postsArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("practiceCell", forIndexPath: indexPath)
// Configure the cell...
cell.textLabel!.text = postsArray[indexPath.row].objectForKey("text") as? String
return cell
}
func fetchData() {
//empty postArray
postsArray = []
//bring data from parse
let query = PFQuery(className: "Practice")
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock { (objects: [PFObject]?, error) -> Void in
if error == nil && objects != nil{
for object in objects! {
self.postsArray.append(object)
print(self.postsArray)
}
}
}
}
}
метод печати после того, как я добавить данные, показывает правильные данные, но первый способ печати в viewDidLoad() не показывают мне ничего. Поэтому мой TableView не показывает мне ничего.
Я прочитал parse doc и искал другие вопросы, кажется, ничего плохого, он не работает.
Не могли бы вы дать мне совет?
Ваши права, он работает. –
Рад, что я могу помочь! – pbush25