iOS Tutorial Downloading JSON into Table View in Swift 3

preview_player
Показать описание
This is a video tutorial in iOS development in Swift 3. This tutorial shows two ways of downloading JSON data and update the TableView into the main UI.

JSON Data Link:

Final project Github Link:

If you have any questions on multi-threading please check this tutorial in the following link:

If you have any questions on the basics of Table View, please check the tutorial of the following link:

For more info, please visit my blog website:
Рекомендации по теме
Комментарии
Автор

I always found separate parts on the Internet but this video just builds all stuff together!!! Such a charm to get things done!!!! Thanks a lot :)

cedong
Автор

Great tutorial. Managed to get around it by creating my own JSON file online.

hamadminmgr
Автор

Thank You ... This tutorial saved me hours of research.

imaratek
Автор

hey this tutorial is awsome,
where will we get JSON data for other resources like movie reviews??

KONDAVENKATASRIVATSAVBCE
Автор

I really enjoyed this tutorial and appreciate the time and effort you put into doing it. You are a great teacher and I look forward to future videos. FYI, about 2 years ago I spent several months writing an iPhone App called "WutzWhere". Swift did not exist then, so I wrote it in Objective-C. I incorporated some of the topics you cover in this tutorial, so it was great to see how the same things were accomplished using Swift. If you wouldn't mind, could you please download the free version of WutzWhere, and give me some feedback and suggestions. Your comments would be much appreciated.

dcosta
Автор

Great tutorial, Do you have a version where you can save it to cache? I added my json with about 25 items and is very choppy when im scrolling down the view. Thanks

jonathanmoore
Автор

great!! Could you include a search bar?

dashcam_cr_bfb
Автор

great Tutorial sir.Can you please do and upload it in objective c sir?

appalanenisuresh
Автор

Excellent.  Do you know how to refresh the data?

cheesetoochalk
Автор

can u make video about how to store Json array object in Sqlite in swift

wordpresswithdhaval
Автор

New JSON parsing is really amazing in Swift 4!

iOSeTutorials
Автор

Hi It's great tutorial,

Trying to implement it, i am getting error in downloadJsonWithURL() method - like Use of unresolved identifier 'URLSession'


Using Xcode 7.2.1 and Swift 2

raviios
Автор

great videos thanks. but how about uploading the image sir?

hizkia
Автор

Thank you so much i did everything exactly like your video and it work perfectly but in class ViewController: you forgot to put in UITableViewDelegate

earlofdemisegaming
Автор

Hey, am so sorry because I keep asking!! I promise this is the last one... Here is when I got soo confused why we didn't say:

let url : NSURL! then url = NSURL ( String: urlString ) like in the other video? Thank you, and I'm sorry again for bothering you!!!

dinamoses
Автор

hi in my project the table view view never get the call function how can i fix it

SureshKumar-ozlj
Автор

Followed your tutorial got all the way to the build and it says: The tableView outlet from the viewController to the UIView is invalid. Outlets cannot be connected to repeating content.

erikgrosskurth
Автор

Hi, Can you help me? I have struggling with this i think now for 4 days. I get the data in the terminal but it doesn't get in the label.

// JSON data
{
"feesten":
{
"naam_feest": "Feest",
"flyer_url": "http:\/\/www.clubvillathalia.nl\/wp-content\/uploads\/sites\/16\/2017\/06\/flyer-boef-20-juli-def.jpg",
"line_up": "SFB - JONNA FRASER - SBMG",
"datum":"2017-07-20",
"plaats": "Rotterdam",
"tijd": "23:00 - 05:00",
"leeftijd": "18+",
"ticket_url": "#",
"stad":"Rotterdam"
}
}


//ViewController.swift
import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {


@IBOutlet weak var tableView: UITableView!

var nameArray = [String]()
var cityArray = [String]()
var flyerArray = [String]()


override func viewDidLoad() {
super.viewDidLoad()

self.downloadJsonWithURL()

// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {

// Dispose of any resources that can be recreated.
}


func downloadJsonWithURL() {
let url = NSURL(string: urlString)
(url as? URL)!, completionHandler: {(data, response, error) -> Void in

if let jsonObj = try? data!, options: .allowFragments) as? NSDictionary {
print(jsonObj!.value(forKey: "feesten"))

if let feestArray = jsonObj!.value(forKey: "feesten") as? NSArray {
for feest in feestArray{
if let feestDict = feest as? NSDictionary {
if let name = feestDict.value(forKey: "naam_feest") {
self.nameArray.append(name as! String)
}
if let name = feestDict.value(forKey: "stad") {
self.cityArray.append(name as! String)
}
if let name = feestDict.value(forKey: "flyer_url") {
self.flyerArray.append(name as! String)
}

}
}
}


self.tableView.reloadData()
})
}
}).resume()
}


func downloadJsonWithTask() {

let url = NSURL(string: urlString)

var downloadTask = URLRequest(url: (url as? URL)!, cachePolicy: URLRequest.CachePolicy.reloadIgnoringCacheData, timeoutInterval: 20)

downloadTask.httpMethod = "GET"

downloadTask, completionHandler: {(data, response, error) -> Void in

let jsonData = try? data!, options: .allowFragments)

print(jsonData)

}).resume()
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return nameArray.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = "cell") as! TableViewCell
cell.nameLabel.text = nameArray[indexPath.row]
cell.stadLabel.text = cityArray[indexPath.row]

let imgURL = NSURL(string: flyerArray[indexPath.row])

if imgURL != nil {
let data = NSData(contentsOf: (imgURL as? URL)!)
cell.imgView.image = UIImage(data: data as! Data)
}

return cell
}

}


// TableViewCell.swift
class TableViewCell: UITableViewCell {

@IBOutlet weak var imgView: UIImageView!

@IBOutlet weak var nameLabel: UILabel!

@IBOutlet weak var stadLabel: UILabel!

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
}

}


Or you can see the whole project in GitHub:

entour-
Автор

like Cemal Sayın i am also facing same problem my json also starting with arrayafter changing code from nsdictionary to nsarray what to do with Value(ForKey "actors").

ManpreetSingh-giqh
Автор

I would like a Tutorial downloading json into a UIPickerView with swift 3

earlofdemisegaming
welcome to shbcf.ru