Swift setText UILabel

时间:2016-02-12 20:17:13

标签: ios swift settext

40.7484445,-73.9878531

Print Out:

let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
        print(responseString)
        self.lbl1.text = String(responseString)

enter image description here

My problem

Optional(2000 TL)

I want to write "2000 TL"

2 个答案:

答案 0 :(得分:4)

The immutable <div ng-controler="oneController"> <span ng-bind="test"></span> </div> is an optional, so you need to unwrap it to get rid of the responseString wrapping.

You can do this e.g. using the nil coalescing operator

Optional(...)

or optional binding

print(responseString ?? "") // Prints "" if responseString == nil
self.lbl1.text = String(responseString ?? "")

答案 1 :(得分:0)

Just try this:

delete m_pio;
m_pio = NULL

Try this for your label:

print(responseString!)

This should remove the optional...