Reputation: 1365
I tried to make a function to load data from Parse with SWIFT.
Data is in the "crcl" className in Parse.
I can't pass PFObject
as AnyObject
in my NSMutableArray
"timeLineData".
I have no code error but the app crash at launching.
What should i do, this is my code :
class TimelineTableViewController: UITableViewController {
var timeLineData:NSMutableArray = NSMutableArray ()
func loadData (){
timeLineData.removeAllObjects()
var findTimeLineData:PFQuery = PFQuery(className: "crcl")
findTimeLineData.findObjectsInBackgroundWithBlock{
(objects:[AnyObject]! , error:NSError!)-> Void in
if !error{
for object:AnyObject in objects! {
self.timeLineData.addObject(object as PFObject)
}
self.tableView.reloadData()
}
}
}
Upvotes: 1
Views: 1080
Reputation: 170
Try to declare your timeLineData
array like so:
var timeLineData = [PFObject]()
This tells Swift that timeLineData
is an array containing PFObject
s.
Then in your completion block use .append
instead of .addObject
like so:
self.timeLineData.append(object as PFObject)
That should do the trick!
Upvotes: 2
Reputation: 4986
You are calling tableView.reloadData from within the block. You need to call dispatch async like so:
dispatch_async(dispatch_get_main_queue()) {
weakSelf!.tableView.reloadData()
}
where weakSelf! is a weak reference to self declared sorta like:
weak var weakSelf : MasterViewController?
where MasterViewController is whatever controller you are in :)
Upvotes: 0