Search code examples
swiftuikit

Can be change UILabel value dynamically in protocol?


I have a problem when after use UILabel with optional value after show custom dialog by xib. after data passed on protocol. it UILabel can't change value because it first time i was develop in swift.

label?.text = data

and 'data' get from pass a protocol value.

But in Android Java. if i used

label.setText(data)

value will be change in label.

maybe, if you can tell me why didn't work it? i was grateful. thank you for help me..


Solution

  • Perhaps it might be a main thread problem for UI updates. Try and see if this works:

    DispatchQueue.main.asnyc {
       label?.text = data
    }