[Solved] Optional String – View Controller


To unwrap do as follow

let strRating =  "\(self.newRateSyting!)\(rateValue!)\(self.ratingTexts[Int(rateValue)]!)"
self.rateLabel?.text = strRating

Example

let value : String? = "4.7"
let review : String? = "very good"

let strRate = "\(value), \(review)"

print("Before unwrap")

print(strRate)

print("\n After unwrap")
let strRate2 = "\(value!), \(review!)"
print(strRate2)

Output:

enter image description here

Note:

If you have array of dict , array of array, dict of dict, dict of array, then you have to unwrap like below:

(arr[index]["key"])! , (arr[index][index])!, (arr["key"]["key"])!, (arr["key"][index])!

Doesn’t matter how much array or dict are complex, always follow above.

If you have still doubt then you can ask.

3

solved Optional String – View Controller