cao0603
(Илья)
1
hi friends, i need your help
i am starting learning swift
i need to connect mysql and show my base in table view using JSON
please correct my code
(
{
code = 1;
id = 1;
kolvo = 2;
user = 3;
},
{
code = 55;
id = 2;
kolvo = 33;
user = zzz;
}
)
JSON
struct Tovar: Codable {
var id : Int?
var code: String?
var kolvo : Int?
}
guard let url = URL(string: "http://myapp:8888/api/inventarizationList.php") else { return }
let session = URLSession.shared
session.dataTask(with: url) { (data, response, error) in
if let response = response {
// print(response)
}
if let data = data {
//print(data)
do {
let json = try JSONSerialization.jsonObject(with: data, options: [])
print(json)
} catch {
print(error)
}
}
}.resume()
and HOW show my JSON in view table
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: idCell) as! MainTableViewCell
cell.titleLabel.text = "Привет"
cell.subTtitleLabel.text = "Как дела"
cell.imageCell.image = #imageLiteral(resourceName: "010-file")