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


how prevent text displaying optional() in swift interpolation?

my text displaying :

---you can switch properties once images optional("ppp") have finished uploading.---

here code

let imageslefttoupload = syncer!.imagestoupload?.count         if(imageslefttoupload != nil && imageslefttoupload! > 0) {             let propertyconfig = syncer!.getpropertyconfig()             var propertynamestr: string = ""             if(propertyconfig != nil && propertyconfig!.propertyname != nil) {                 propertynamestr = "from \(propertyconfig!.propertyname)"             }             messagetext.text = "you can switch properties once images\(string(describing: propertynamestr)) have finished uploading."         } 

use optional binding safely unwrap optionals, use string interpolation on 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 switch properties once images\(propertyname) have finished uploading." 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -