Swifty JSON UITableView original error

I followed the tutorial from Ray Wenderlich . However, I am not getting the array directly in the UITableView. Loading JSON into UITableView takes about 20 seconds. But in the Console Log, the array is available. I am 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] Alert about getting memory. ["Coffeehuisie", "Caffee Allee | Stadsrestaurant", "Ketelhuis", "Monk Eindhoven", "Radio Royaal", "PopEi Food and Drink", "Tijdelijk restaurant", "NATLAB", "Bagel and Juice," Confectionery club "," Intellegentia ICE "," Onder de leidingstraat "," Keukenconfessies "]

Error log for each line of the array (after 20 seconds):

2015-09-24 09: 46: 09.579 TopApps [660: 180231] This application changes the autostart mechanism from a background thread, which can lead to engine damage and strange crashes. This will throw 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 Base 0x0000000183bca5d8 + 88 4 Basis 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)

+3


source to share


1 answer


dispatch_async(dispatch_get_main_queue(), {
    // put your code here  load the JSON into the UITableView
})

      



+1


source







All Articles