1 Reply
      Latest reply: Dec 28, 2016 4:19 PM by eskimo RSS
      jarv81178 Level 1 Level 1 (0 points)

        I have reused a function that was originally working for a tableview but I just need it to work on a single ViewController, my text labels are not being set properly, can someone please help? [code] @IBOutlet var mainTitle: UILabel!     @IBOutlet var subMainTitle: UILabel!         var selectedMain: String?     var theURL: String!         override func viewDidLoad() {         super.viewDidLoad()         fetchMain()         // Do any additional setup after loading the view.     }     func fetchMain(){         //selectedTown = "Brighton"         let finalselectedMain = selectedMain!.replacingOccurrences(of: " ", with: "+")         theURL = "http://www.mypubspace.com/json/getbusiness.php?id=\(finalselectedMain)"         let urlRequest = URLRequest(url: URL(string: theURL)!)         let task = URLSession.shared.dataTask(with: urlRequest) { (data,response,error) in             if error != nil{                 print(error)                 return             }                         do {                 let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! [String : AnyObject]                                 if let articlesFromJson = json["articles"] as? [[String:AnyObject]] {                     for articleFromJSON in articlesFromJson{                         let article = Article()                         if let title = articleFromJSON["CompanyName"] as? String, let desc = articleFromJSON["SICDescriptions"] as? String, let id = articleFromJSON["id"] as? String {                             self.mainTitle.text = title                             self.subMainTitle.text = desc                         }                                             }                 }                 DispatchQueue.main.async {                                     }                                             }catch let error{                 print(error)             }         }             } [/code]

        • Re: lebels not being set in JSON loop
          eskimo Apple Staff Apple Staff (5,995 points)

          Please reformat your question with the code marked up as a code block; it’s very hard to read as things stand.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"