I am trying to pass the information from the json variable parseJSON["timeStamp"] as! String
to strgetTimeStamp
, but I tried to add to the return value it keeps bypassing and the return value is always 'nothing'.
When I use print(strgetTimeStamp)
after strgetTimeStamp = parseJSON["timeStamp"] as! String
, it shows the information.
func checkStamp(AppID:String)-> String{
//send data to server side
let myUrl = NSURL(string: "http://chill-lax.website/ReCap/fcm/timeChkRelease.php?apptype=\(AppID)")
let request = NSMutableURLRequest(URL: myUrl!)
request.HTTPMethod = "POST"
var strgetTimeStamp = "nothing"
let task = NSURLSession.sharedSession().dataTaskWithRequest(request)
{
data, response, error in
if error != nil{
print("error=\(error)")
return
}
do {
let json = try NSJSONSerialization.JSONObjectWithData(data!, options:NSJSONReadingOptions.MutableContainers) as? NSDictionary
// Your code here
if let parseJSON = json{
var isTimeStamp :Bool = false
let resultValue = parseJSON["status"] as! String
if (resultValue=="Success"){isTimeStamp = true}
if(resultValue=="Success")
{
strgetTimeStamp = parseJSON["timeStamp"] as! String
print(strgetTimeStamp )
}
}
else{
print("Error - ");
}
}
catch
{
print(error)
}
}
task.resume()
return strgetTimeStamp ///this returns nothing
}
*vadian - I am trying to return a value, and the example you showed to me is adding to an NSarray, the json value is only only value. Also this is more obj C ish****
Please can someone tell me where I am going wrong!