SwiftDeveloper
SwiftDeveloper

Reputation: 7366

Swift get tableview array count and place it textview

Hello i have tableview and parsing json and i have textview, i want to add my tableview items count into textview but gives me ;

fatal error: unexpectedly found nil while unwrapping an Optional value

Error

My codes here

var clientList = [String]()

let json = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers) as? NSArray

            if let parseJSON = json {

                self.clientList = parseJSON as! [String]
                self.clientsmessage.text = "You have \(self.clientList.count) client"

            }

Upvotes: 0

Views: 59

Answers (1)

Breek
Breek

Reputation: 1441

Looks like your self.clientsmessage doesn't instantiate correctly, please check the part.

OR

if self.clientsmessage != nil {
    self.clientsmessage.text = "You have \(self.clientList.count) client"
}

Upvotes: 1

Related Questions