json - How to unwrap optional in swift3 -
this question has answer here:
var people = [mydata]() override func prepare(for segue: uistoryboardsegue, sender: any?) { if segue.identifier == "theresegue" , let destinationnavigationcontroller = segue.destination as? uinavigationcontroller , let nextscene = destinationnavigationcontroller.topviewcontroller as? commentview , let indexpath = self.mytable.indexpathforselectedrow { let selectedvehicle = people[indexpath.row] nextscene.postid = (selectedvehicle.value(forkey: "id") as? string)! print(nextscene.postid) nextscene.posttype = (selectedvehicle.value(forkey: "ptype") as? string)! print(nextscene.posttype) } }
when trying do
let jsonurl = "https://www.zdoof.com/api/ztimeline/add_post_comment?" let jsonurlwithparameters = jsonurl + "comment=\(string(describing: self.commenttext.text!))" + "&post_id=\(postid)" + "&post_type=\(posttype)" + "&created_by=4490" + "&created_on=\(joinstring)" print(jsonurlwithparameters)
it printing
optional(8167)
optional(1)
so how delete "optional"
simply put ! after optional value want unwrap.
ex:
var integer: int? = 5 print(integer) // print out optional(5) print(integer!) // print out 5
you should careful though; rather use
if let unwrappedvalue = integer { print(unwrappedvalue) }
that prints out value if it's not optional.
Comments
Post a Comment