-1
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 I am trying to 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 is printing

Optional(8167)

Optional(1)

https://www.zdoof.com/api/zTimeline/add_post_comment?Comment=hzbxhjxjx&Post_id=Optional(8167)&Post_type=Optional(1)&Created_by=4490&Created_on=18%2FAug%2F2017+17%3A42%3A43

So how to delete "optional"

Community
  • 1
  • 1
Tapan Raut
  • 73
  • 7

1 Answers1

0

Simply put ! after the optional value you want to unwrap.

Ex:

var integer: Int? = 5

print(integer) // would print out Optional(5)

print(integer!) // would print out 5

You should be careful though; rather use

if let unwrappedValue = integer {
  print(unwrappedValue)
}

that only prints out the value if it's not optional.

Matt Harris
  • 177
  • 9