0

im using parse in my project, put i faceing issue here is my code :

 func getIdByItemName (name:String) -> String
{
    let Query = PFQuery(className: "Class") 
        .whereKey("name", equalTo: name)
    var QueryObject = Query.findObjects()
    var findId:String = "????"
    for quer in QueryObject!
    {
         findId = String(quer.objectId)
    }
    print("The object id id : \(findId)")
    return findId
}

my issue is the returned values will be like this :

Optional("l7wpt4slip")

my question is how can i remove optional and keep only object id as String like this ?? :

l7wpt4slip

bsm-2000
  • 265
  • 2
  • 13
  • possible duplicate of [swift printing optional variable](http://stackoverflow.com/questions/25846561/swift-printing-optional-variable) – Aks Sep 02 '15 at 07:04

1 Answers1

0

Here is the safe way to unwrap an optional values:

for quer in QueryObject!
    {
        //unwrap it with if let.
        if let temp = String?(quer.objectId){
            findId = temp
        }
    }
Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165