I'm trying to recieve data from a server to initialize my app. However sometimes due to the network problem I cannot recieve any data. So at this time, I need to show an alert and exit the app. Here's my code:
override func viewDidLoad() {
super.viewDidLoad()
/
var params = Dictionary<String, String>();
params["path"] = "/";
let response = ApiRequest.get(ApiRequest.LIST_FOLDER, params: params);
if (response?.objectForKey("succ") == nil) {
self.presentViewController(UIAlertController.init(title: "Network Error", message: "No recieved data", preferredStyle: UIAlertControllerStyle.Alert), animated: true, completion: nil);
abort();
}
if (response?.objectForKey("succ") as! String == "0") {
UIAlertView(title: "Server Error", message: "Unable to process the request", delegate: nil, cancelButtonTitle: "Cancel").show();
abort();
}
folderList = FolderList(folders: response?.objectForKey("msg") as! NSDictionary);
}
But actually no alert view was shown when no network connection. Anybody knows why this happened?
PS: if I change "if (response?.objectForKey("succ") == nil)" to "if (response == nil)", it doesn't work. Even response is actually nil, it doesn't goes into the if block.