Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func file_get_content(page: String) throws -> String {
- guard let url = URL(string: page) else {
- throw "Cannot load that URL"
- }
- guard let contents = try? String(contentsOf: url) else {
- throw "Cannot load content from \(url)"
- }
- if (contents.isEmpty) { throw "Content of \(url) is empty" }
- return contents
- }
- // how to use
- do {
- let content = try file_get_content(page: "") // اذا مافيه اي خطأ كمل
- } catch {
- // اذا فيه غلط خلص طلع رساله
- let alert = UIAlertController(title: "DBMovie", message: error.localizedDescription, preferredStyle: .alert)
- alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
- self.present(alert, animated: true, completion: nil)
- }
Add Comment
Please, Sign In to add comment