mc44 mc44 - 1 year ago 91
JSON Question

Swift Alamofire JSON Parsing

I'm making JSON parsing with Alamofire. I can get data from web service. I want to set label. I can print any data with "print()" function. But i can not set to label. Please help me.

My code is here.

Alamofire.request(.GET, "url").validate().responseJSON { response in
switch response.result {
case .Success:
if let value = response.result.value {
let jsonObject = JSON(value)

// this row is working.
// i can not print to label here
if let titleValue = jsonObject["Title"].string {
self.newsTitleLabel.text = titleValue

case .Failure(let error):

//print result:
Bolu Dağı'nda bayram tatili yoğunluğu
//if blok:
fatal error: unexpectedly found nil while unwrapping an Optional value

Answer Source

You mean the crash is on the line self.newsTitleLabel.text = titleValue, right? Make sure that your newsTitleLabel does exists either it is IBOutlet/variable.