BandarHelal

Untitled

Jun 8th, 2021 (edited)
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.88 KB | None | 0 0
  1.     func file_get_content(page: String) throws -> String {
  2.         guard let url = URL(string: page) else {
  3.             throw "Cannot load that URL"
  4.         }
  5.         guard let contents = try? String(contentsOf: url) else {
  6.             throw "Cannot load content from \(url)"
  7.         }
  8.         if (contents.isEmpty) { throw "Content of \(url) is empty" }
  9.        
  10.         return contents
  11.     }
  12. // how to use
  13.         do {
  14.             let content = try file_get_content(page: "") // اذا مافيه اي خطأ كمل
  15.         } catch {
  16.             // اذا فيه غلط خلص طلع رساله
  17.             let alert = UIAlertController(title: "DBMovie", message: error.localizedDescription, preferredStyle: .alert)
  18.             alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
  19.             self.present(alert, animated: true, completion: nil)
  20.         }
Add Comment
Please, Sign In to add comment