I have to file inside my project, 1 - view.swift and the 2 - login.swift. I have a function inside my login.swift which will get a token from a site that i provide. Then I need that token which my function gets from the site and i want to use it in my view.swift, But I cant't get it outside that func no matter what I do.
The code is like this :
struct universal{
static var token = String()
static var passkey = String()
}
class LoginManager {
let loginURL = "http://somesite.com"
func login() {
let parameters: Parameters = [
"username": "username",
"password": "password",
"device": "gtv",
"redir": "0"
]
Alamofire.request(loginURL, method: .get, parameters: parameters).responseJSON { (response) in
let jsonRes = JSON(data: response.data!)
var token = jsonRes["token"].stringValue
// the value of universal.token is not print outside of this func nither the token. But both of them can get the value here and when printing them it shows the value
universal.token = jsonRes["token"].stringValue
}
}
Im newbie so don't be mean. I just try to learn.
The question is how can i get only value not just closure or use entire func in other class if possible