Reputation: 349
I've followed the tutorial from Ray Wenderlich. However I'm not getting the array direct into the UITableView. It takes now about 20 seconds to load the JSON into the UITableView. But in the Console log the Array is direct available. I'm working in Swift 2.0.
@IBOutlet var tableView: UITableView!
let textCellIdentifier = "CoffeeLocations"
var apps : [String] = []
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
// Do any additional setup after loading the view.
DataManager.getTopAppsDataFromItunesWithSuccess { (iTunesData) -> Void in
let json = JSON(data: iTunesData)
if let appArray = json[].array {
for appDict in appArray {
let appName: String? = appDict["name"].string
self.apps += ["\(appName!)"]
}
print(self.apps) // Here he print directly to the console log
self.tableView.reloadData()
}
}
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return apps.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(textCellIdentifier, forIndexPath: indexPath) as! TableViewCell
let row = indexPath.row
cell.titleLabel!.text = apps[row]
//cell.detailLabel!.text = description[row] Later I want to add a second rule
return cell
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
Error log (directly):
2015-09-24 09:45:31.493 TopApps[660:180190] Received memory warning. ["\'t Koffiehuisje", "Caffee Allee | Stadsrestaurant", "Ketelhuis", "Monk Eindhoven", "Radio Royaal", "PopEi Food & Drinks", "Tijdelijk restaurant", "NATLAB", "Bagel & Juice", "Pastry club", "Intellegentia ICE", "Onder de leidingstraat", "Keukenconfessies"]
Error log for every line in the array (after 20 seconds):
2015-09-24 09:46:09.579 TopApps[660:180231] This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release. Stack:( 0 CoreFoundation 0x0000000182bb0f74 + 148 1 libobjc.A.dylib 0x00000001977a3f80 objc_exception_throw + 56 2 CoreFoundation 0x0000000182bb0ea4 + 0 3 Foundation 0x0000000183bca5d8 + 88 4 Foundation 0x0000000183a4ca1c + 36 5 UIKit 0x000000018820b958 + 64 6 UIKit 0x00000001881022d8 + 240 7 UIKit 0x0000000188101b8c + 116 8 UIKit 0x0000000188101a18 + 504 9 UIKit 0x00000001884098e0 + 228 10 UIKit 0x0000000188100458 + 412 11 UIKit 0x00000001881fae14 + 1440 12 UIKit 0x00000001881efab8 + 216 13 UIKit 0x000000018810300c + 644 14 QuartzCore 0x0000000187909f14 + 148 15 QuartzCore 0x0000000187904b20 + 292 16 QuartzCore 0x00000001879049e0 + 32 17 QuartzCore 0x000000018790407c + 252 18 QuartzCore 0x0000000187903dd0 + 516 19 QuartzCore 0x0000000187932f48 + 236 20 libsystem_pthread.dylib 0x00000001981b21e8 + 584 21 libsystem_pthread.dylib 0x00000001981b1d60 + 136 22 libsystem_pthread.dylib 0x00000001981b1544 pthread_mutex_lock + 0 23 libsystem_pthread.dylib 0x00000001981b1028 start_wqthread + 4 )
Upvotes: 3
Views: 141
Reputation: 88
dispatch_async(dispatch_get_main_queue(), {
// put your code here load the JSON into the UITableView
})
Upvotes: 1