Reputation: 1496
I am working with Alamofire to retrieve data from a web API:
func getData(completionHandler: (responseObject: NSDictionary?) -> ()) -> () {
Alamofire.request(.GET, "http://example.com/api/resource/")
.validate()
.authenticate(user: user, password: password)
.responseJSON { (request, response, responseObject) in
switch responseObject {
case .Success:
print("Validation Successful")
completionHandler(responseObject: responseObject as? NSDictionary)
case .Failure(_, let error):
print(error)
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
getData { (str, error) in
if str != nil {
print(str)
} else {
print(error)
}
}
}
When I run the code, it gives an error, the error is shown below
Command failed due to signal: Segmentation fault: 11
I don't know what is wrong with it and how to fix it. Any suggestions are very much appreciated.
Upvotes: 3
Views: 1247
Reputation: 16643
You are calling getData
incorrectly. You are passing the completion handler two parameters (str, error
when it only takes a single responseObject
.
Upvotes: 3
Reputation: 6077
Had a similar problem while using Alamofire once. I deleted and reimported framework and then it worked. Looked like the compiler had some problem with that.
Anyway try to Product > Clean
your project also.
If it still doesn't work try to set breakpoints
(or simply comment) your nested section to spot where is exactly the failure.
Upvotes: 2