pau-riquelme

Untitled

Jan 29th, 2018
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.64 KB | None | 0 0
  1. //1
  2. self.sendNetworkOperation(
  3.     params: ["Token":"Bearer aaaaaaaaaa","limit": 100],
  4.     completion: { (res) in
  5.         switch res.0{ //6
  6.             case true:
  7.                 //success
  8.                 break
  9.             case false:
  10.                 //error
  11.                 break
  12.             }
  13.     })
  14.  
  15. func isReachable() -> Bool {
  16.     let reachability = Reachability()! //3
  17.    
  18.     if reachability.isReachable{ //4
  19.         return true
  20.     }
  21.    
  22.     return false
  23. }
  24.  
  25. func sendNetworkOperation(
  26.     params: Dictionary<String,Any>,
  27.     completion: ((Bool,String?)->())){
  28.     //2
  29.     if self.isReachable(){
  30.         //5
  31.         //send operation
  32.         completion(true, nil)
  33.     } else {
  34.         //5
  35.         completion(false, "Error, network is not reachable")
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment