title: how to convert Data to Int in swift
body: <p>I'm coding in Swift. API returns a Data which need to be converted to Int! what should I do?</p>
  
  <p>the response that I need looks like::</p>
  
  <blockquote>
    <p>12345</p>
  </blockquote>
  
  <p>but the think I get when I print data is :</p>
  
  <blockquote>
    <p>Optional(5 bytes)</p>
  </blockquote>
  
  <p>API returns an Int (not JSON)</p>
  
  <pre><code>//send HTTP req to register user
          let myUrl = URL(string: "http://app.avatejaratsaba1.com/api/Person/Create")
          var request = URLRequest(url: myUrl!)
          request.httpMethod = "POST" // compose a query string
          request.addValue("application/json", forHTTPHeaderField: "content-type")
          request.addValue("application/json", forHTTPHeaderField: "Accept")
  
          let postString = ["name" : name.text!,
                            "isLegal" : FinalLegalSegment,
                            "codeMelli" : National_ID.text! ] as [String : Any]
  
  
  do {
              request.httpBody = try JSONSerialization.data(withJSONObject: postString, options: .prettyPrinted)
          }catch let error {
              print(error.localizedDescription)
              self.DisplayMessage(UserMessage: "1Something went wrong , please try again!")
              return
          }
  
          let task = URLSession.shared.dataTask(with: request)
          {
              (data : Data? , response : URLResponse? , error : Error?) in
  
              self.removeActivtyIndicator(activityIndicator: MyActivityIndicator)
  
              if error != nil
              {
                  self.DisplayMessage(UserMessage: "2Could not successfully perform this request , please try again later.")
                  print("error = \(String(describing : error))")
                  return
              }
              else
              {
  
                  print("////////////////////////////////")
                  print("data has been sent")
  
              }
          }
  
  
  
          task.resume()
  </code></pre>