Wan Jern Wan Jern - 6 months ago 38
Swift Question

UILabel Value of type 'String' have no member 'text' (Static Custom Cell)

I'm getting user information from json but when i assign the values to my labels, it show the error (Value of type 'String' have no member 'text').

Is it because the Custom static table cell? How to fix it? Sorry my foundation is not good...

Screenshot 1

Screenshot 2

Answer Source

Use different variable names. Its good practise to have unique variable names

As the variable names are same as variable values you are getting the error

UILabel has name empNameLabel : UILabel(In viewDidLoad) and value also has same name.


let empNameLabel = user!["crew_name"] as? String //conflicting name with UILabel iboutlet


let empNameValue = user!["crew_name"] as? String //variable name is unique

Also you should not force unwrap options(user in your case)

it should be

var empNameValue = ""
if let unwrappedUser = user {
    if let empNameValue = unwrappedUser["crew_name"] as? String {
        empNameLabel.text = empNameValue //assign value to UILabel
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download