title: Getting nil value when passing value to api
body: <p>Things i did :</p>
  
  <ol>
  <li><p>I have one url api which will display some data in my table view.
  2.And i fetch the particular value called "_id" from my url and i just pass that value to one custom class object.</p></li>
  <li><p>Then i am passing that class object value to one of my another api calling url.In there i getting the value as nil.</p></li>
  </ol>
  
  <p>Here is the code that ia m populating the data to my table view.And i am taking the particular value from api "_id" And i am storing that value to one custom class object :</p>
  
  <pre><code>// Showing favourites
      func populateFavourites()
      {
          let token = NSUserDefaults.standardUserDefaults().valueForKey("access_token") as! String
  
          let headers = ["x-access-token": token]
  
          let request = NSMutableURLRequest(URL: NSURL(string: "some url")!)
          request.HTTPMethod = "GET"
          request.allHTTPHeaderFields = headers
  
          let session = NSURLSession.sharedSession()
          let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -&gt; Void in
  
              if (error != nil)
              {
                  print(error)
              }
              else
              {
                  dispatch_async(dispatch_get_main_queue(),{
                      if let json = (try? NSJSONSerialization.JSONObjectWithData(data!, options: [])) as? Dictionary&lt;String,AnyObject&gt;
                      {
  
                          print("Success Got Json Data")
  
                          let success = json["success"] as? Int
  
                          if(success == 1)
                          {
                              let jsonData = json["data"] as! NSArray
  
                              if(jsonData.count&gt;0)
                              {
  
  
  
                                  for items in jsonData
                                  {
                                      let BObj = items as! NSDictionary
  
                                      let BusinessDetails = BObj.valueForKey("business_id") as! Dictionary&lt;String,AnyObject&gt;
  
                                      self.FavBusinessValues.append(Businessdata(json:BusinessDetails))
                                                                        print(items)
  
                                       let FavId = BObj.valueForKey("_id") as! String
  
  
                                      self.FavDelete?.FavIds = FavId
  
                                      print(FavId)
  
  
  
  
                                  }
  
                                  self.tableView.reloadData()
  
                              }
                              else
                              {
                                  self.CreateNoDataLabel()
                              }
                          }
                          else
                          {
                              let message = json["message"] as? String
  
                              print("Fav Message ",message)
  
                              let alert = UIAlertController(title: "Error: ", message: message, preferredStyle: UIAlertControllerStyle.Alert)
  
                              // add an action (button)
                              alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
  
                              // show the alert
                              self.presentViewController(alert, animated: true, completion: nil)
                          }
                      }
                  })
              }
          })
          dataTask.resume()
  
      }
  </code></pre>
  
  <p>In my above code i am taking the particular value "_id" and i am passing to my custom objet class :</p>
  
  <pre><code> let FavId = BObj.valueForKey("_id") as! String
   self.FavDelete?.FavIds = FavId
   print(FavId)
  </code></pre>
  
  <p>This <code>print(FavId)</code> is printing the correct value.Here is my cutom class object that store that value of "_id" :</p>
  
  <pre><code>import Foundation
  class Favdelete
  {
          var FavIds : String?
  
  
      init(json:String)
      {
  
          self.FavIds = json as? String
  
      }
  }
  </code></pre>
  
  <p>Then i am passing the "_id" objet value <code>FavIds</code> to my one of my api calling.That code is under below :</p>
  
  <pre><code> func apidelete () {
  
  
  
             let Favouriteid = FavDelete?.FavIds
                             print(Favouriteid)
  
                let userToken = NSUserDefaults.standardUserDefaults().valueForKey("access_token") as! String;
          print(userToken)
  
  
                          let headers = [
                              "x-access-token": userToken,
                              "cache-control": "no-cache",
                              "postman-token": "81fbd1fc-c333-3ceb-272a-a9ecffb2dad2",
                              "content-type": "application/x-www-form-urlencoded"
                          ]
  
  
  
  
          let FBI = "favourite_id="+Favouriteid!
  
  
          let postData = NSMutableData(data: FBI.dataUsingEncoding(NSUTF8StringEncoding)!)
  
                          let request = NSMutableURLRequest(URL: NSURL(string: "some url")!,
                                                            cachePolicy: .UseProtocolCachePolicy,
                                                            timeoutInterval: 10.0)
  
          let session = NSURLSession.sharedSession()
          let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -&gt; Void in
              if (error != nil) {
                  print(error)
              } else {
                  let httpResponse = response as? NSHTTPURLResponse
                  print(httpResponse)
                  dispatch_async(dispatch_get_main_queue(),{
                      if let json = (try? NSJSONSerialization.JSONObjectWithData(data!, options: [])) as? Dictionary&lt;String,AnyObject&gt;
                      {
  
                          print("Success Got Json Data");
  
                          let success = json["success"] as? Int;
  
                          var message:String = "";
  
                          if(success == 1)
                          {
                              message = json["message"] as! String;
                          }
                          else
                          {
                              message = json["message"] as! String;
                          }
  
                          print(message);
  
                          let alert = UIAlertController(title: "Message from server", message: message, preferredStyle: UIAlertControllerStyle.Alert)
  
                          alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
  
                          self.presentViewController(alert, animated: true, completion: nil)
  
                      }
                  })
  
              }
          })
  
          dataTask.resume()
  
  
  
  
      }
  </code></pre>
  
  <p>When i try to print this :</p>
  
  <pre><code>let Favouriteid = FavDelete?.FavIds
    print(Favouriteid)
  </code></pre>
  
  <p>I ma getting crash and it says nil printing in my console.</p>
  
  <p>Can any one please help me out.!!</p>
  
  <p>Updated :</p>
  
  <p>Under my first function method.That is when i get the particular value and store that value to my custom object .I just print it.I am getting nil there too.</p>
  
  <p>The line is :</p>
  
  <pre><code>let FavId = BObj.valueForKey("_id") as! String
   self.FavDelete?.FavIds = FavId
  print(self.FavDelete?.FavIds)
  </code></pre>
  
  <p>Its printing nil</p>
  
  <p>Updated :</p>
  
  <p><a href="https://i.stack.imgur.com/FCjQR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FCjQR.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/oAQDP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oAQDP.png" alt="enter image description here"></a></p>