-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewController.swift
58 lines (44 loc) · 1.72 KB
/
ViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// ViewController.swift
// DemoAPI
//
// Created by Apple on 06/11/19.
// Copyright © 2019 TechMade. All rights reserved.
//
import UIKit
import Alamofire
class ViewController: UIViewController {
@IBOutlet weak var tblView: UITableView!
var listData : weatherData?
override func viewDidLoad() {
super.viewDidLoad()
callAPI()
// Do any additional setup after loading the view.
}
func callAPI()
{
Alamofire.request(baseURL, method: .get, encoding: JSONEncoding.default)
.responseJSON { response in
switch response.result {
case .success(let json):
print(json)
DispatchQueue.main.async {
let jsonDecode = JSONDecoder()
do{
let user = try jsonDecode.decode(weatherData.self, from: response.data!)
self.listData = weatherData(cod: user.cod, message: user.message, cnt: user.cnt, list: user.list)
DispatchQueue.main.async {
self.tblView.reloadData()
}
}
catch
{
print(error.localizedDescription)
}
}
case .failure(let error):
print(error.localizedDescription)
}
}
}
}