I have this class:
class AlamofireService {
static let alamofireService = AlamofireService()
private init() {
}
internal func makePostServiceRequest(url: String, parameters: AnyObject, completed: RequestComplete) -> RestResponse {
let restResponse = RestResponse()
Alamofire.request(.POST, URL_BASE, parameters: [IOS_PARAMS : parameters], encoding:.JSON).validate()
.responseJSON
{
response in switch response.result
{
case .Success(let JSON):
print("Success with JSON: \(JSON)")
restResponse.success = true
restResponse.JSONString = JSON as? String
let response = JSON as! NSDictionary
print(response)
var array = NSMutableArray!()
array = response.valueForKey("countryList") as? NSMutableArray
case .Failure(let error):
print("Request failed with error: \(error)")
restResponse.success = false
restResponse.error = error.localizedFailureReason
restResponse.responseCode = error.code
}
}
return restResponse
}
}
And when i'm trying to call the function with this code:
AlamofireService.alamofireService.makePostServiceRequest(URL_BASE, parameters: params!) { () -> () in
if (restResponse.succes == true){
let user = Mapper<User>().map(restResponse.JSONString)
print(user?.username)
self.performSegueWithIdentifier("tabBarIdentifier", sender: nil)
}
print("Something went wrong")
}
}
I get the error from the title on 3th and 4th line. I don't understand why i can't access it.
Even if i have a closure which allows me to call the block of code after makePostServiceRequest is done, it suppose that i can use the restResponse constant.
I need something that will help me to know whether is the case successful or not, but out of function with switch statement
Aucun commentaire:
Enregistrer un commentaire