daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Dec 10th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. enum CodingKeys : String, CodingKey {
  2.         case data = "data"
  3.  
  4.     }
  5. }
  6.  
  7. struct Article_Data: Decodable {
  8.     let title: String
  9.     let image: String
  10.     let cat: Category
  11.  
  12.      enum CodingKeys : String, CodingKey {
  13.         case title = "title"
  14.         case image = "image"
  15.         case cat = "cat"
  16.     }
  17.  
  18. }
  19.  
  20. struct Category: Decodable {
  21.     let type: String
  22.      enum CodingKeys : String, CodingKey {
  23.         case type = "title"
  24.     }
  25. }
  26.    
  27. var arrData = [Article_Data]()
  28.  
  29. func getCoinData() {
  30.     let jsonURL = "https://abctv.kz/ru/api/v1/getMainList"
  31.     guard let url = URL(string: jsonURL) else { return }
  32.  
  33.     URLSession.shared.dataTask(with: url) { [unowned self] (data, response, error) in
  34.         guard let data = data else { return }
  35.         do {
  36.             let decoder = JSONDecoder()
  37.             decoder.keyDecodingStrategy = .convertFromSnakeCase
  38.             let data_new = try decoder.decode(News_data.self, from: data)
  39.           }
  40.  
  41.             DispatchQueue.main.async {
  42.                 self.arrData = data_new.data
  43.                 self.tableview.reloadData()
  44.             }
  45.  
  46.         } catch {
  47.             print("Error is : n(error)")
  48.         }
  49.         }.resume()
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top