Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import UIKit
  2. import Foundation
  3.  
  4. // MARK: - math
  5. struct Math: Codable {
  6. let classes: [Class]?
  7. }
  8.  
  9. // MARK: - Class
  10. struct Class: Codable {
  11. let calculus: [Calculus]?
  12. }
  13.  
  14. // MARK: - Calculus
  15. struct Calculus: Codable {
  16. let question: String?
  17. let answer: Answer?
  18. }
  19.  
  20. enum Answer: String, Codable {
  21. case answer = "answer"
  22. }
  23. let url = URL(string: "https://1416baef.ngrok.io")
  24. let request = NSMutableURLRequest(url:url!);
  25. let task = URLSession.shared.dataTask(with: request as URLRequest) { (data, response, error) in
  26. if error == nil {
  27. let math = try? JSONDecoder().decode(Math.self, from: data!)
  28.  
  29. for i in (0...math!.classes![0].calculus!.count) {
  30. print(math!.classes![0].calculus![i].question!)
  31. print(math!.classes![0].calculus![i].answer!)
  32. }
  33. }
  34. else {
  35. print(error ?? "error within error")
  36. }
  37. }
  38. task.resume()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement