I'm trying to get an array from the method down below. The method parseJSONResult
returns an array, and I've checked that it does this correctly with a print
and it absolutely does. The variable self.jobOpenings
is an array property in the class. I have this variable because I want to use it after I've called doNetworking()
in another class. However, .count
gives me 0 if called outside the if httpResponse.statusCode == 200
statement. I hope I have given enough information for anyone to help me out, thanks.
func doNetworking() {
dataTask?.cancel()
let url = NSURL(string: "https://example.com/")
let session = NSURLSession.sharedSession()
dataTask = session.dataTaskWithURL(url!, completionHandler: {
data, response, error in
if let error = error {
if error.code == -999 {
print(error)
}
} else if let httpResponse = response as? NSHTTPURLResponse {
if httpResponse.statusCode == 200 {
let parsedData = self.parseJSONData(data!)
self.jobOpenings = self.parseJSONResult(parsedData!)
return
}
}
})
dataTask?.resume()
}