I have made a mistake which I can't find. The array (class level) gets empty just before returning it.
private func loadUserData() {
// We're getting user info data from JSON response
let session = Twitter.sharedInstance().sessionStore.session()
let client = TWTRAPIClient.withCurrentUser()
let userInfoURL = "https://api.twitter.com/1.1/users/show.json"
let params = ["user_id": session?.userID]
var clientError : NSError?
let request = client.urlRequest(withMethod: "GET", url: userInfoURL, parameters: params, error: &clientError)
client.sendTwitterRequest(request) { (response, data, connectionError) -> Void in
if connectionError != nil {
print("Error: \(connectionError)")
}
do {
let json = JSON(data: data!)
if let userName = json["name"].string,
let description = json["description"].string,
let followersCount = json["followers_count"].int,
let favouritesCount = json["favourites_count"].int,
let followingCount = json["friends_count"].int,
let lang = json["lang"].string,
let nickname = json["screen_name"].string {
self.userData.append(userName)
self.userData.append(description)
self.userData.append(String(followersCount))
self.userData.append(String(favouritesCount))
self.userData.append(String(followingCount))
self.userData.append(lang)
self.userData.append(nickname)
print(self.userData)
}
}
}
print(userData)
}
I'm just trying to access to its values from other part of the code and can't do it as it gets empty. I can see the array data the first time I print it, but not in the second one. Thank you very much!