Reputation:
let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
print(responseString)
self.lbl1.text = String(responseString)
Print Out:
Optional(2000 TL)
My problem
> "self.lbl1.text = String(responseString)" Optional( write.
I want to write "2000 TL"
Upvotes: 1
Views: 1293
Reputation: 6796
Just try this:
print(responseString!)
Try this for your label:
self.lbl1.text = responseString!
This should remove the optional...
Upvotes: 1
Reputation: 73206
The immutable responseString
is an optional, so you need to unwrap it to get rid of the Optional(...)
wrapping.
You can do this e.g. using the nil coalescing operator
print(responseString ?? "") // Prints "" if responseString == nil
self.lbl1.text = String(responseString ?? "")
if let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding) {
print(responseString)
self.lbl1.text = String(responseString)
}
Upvotes: 4