How do I prevent my text from displaying Optional() in the Swift interpolation?

前端 未结 3 819
星月不相逢
星月不相逢 2021-01-28 09:24

How do I prevent my text from displaying Optional() in the Swift interpolation?

My text displaying is :

---You can only switch properties once all images from Op

3条回答
  •  离开以前
    2021-01-28 10:09

    Use optional binding to safely unwrap the optionals, then use String interpolation on the non-optional value.

    guard let imagesLeftToUpload = syncer?.imagesToUpload?.count, imagesLeftToUpload > 0 else {return}
    guard let propertyConfig = syncer?.getPropertyConfig(), let propertyName = propertyConfig.propertyName else {return}
    messageText.text = "You can only switch properties once all images\(propertyName) have finished uploading."
    

提交回复
热议问题