From fb8b7bd1f40310891351f14a80883f1218283531 Mon Sep 17 00:00:00 2001 From: MING <54872601+1998code@users.noreply.github.com> Date: Tue, 24 Sep 2024 16:41:01 +0800 Subject: [PATCH] Add Swift Code Example (#495) * Add Swift Example * Update README.md Co-authored-by: Martin Cech --------- Co-authored-by: Martin Cech --- README.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3dde9d6..b893448 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Changelog Example Usage ============= -TOC: [Python](#python), [PHP](#php), [Go](#go), [Ruby on Rails](#ruby-on-rails), [NodeJS](#nodejs), [C#](#c), [bash](#bash), [Java](#java) +TOC: [Python](#python), [PHP](#php), [Go](#go), [Ruby on Rails](#ruby-on-rails), [NodeJS](#nodejs), [C#](#c), [bash](#bash), [Java](#java), [Swift](#swift) ### Python ```Python @@ -214,3 +214,27 @@ public static boolean isDisposable(InternetAddress contact) throws AddressExcept return DISPOSABLE_EMAIL_DOMAINS.contains(domain); } ``` + +### Swift +contributed by [@1998code](https://github.com/1998code) + +```swift +func checkBlockList(email: String, completion: @escaping (Bool) -> Void) { + let url = URL(string: "https://raw.githubusercontent.com/disposable-email-domains/disposable-email-domains/master/disposable_email_blocklist.conf")! + let task = URLSession.shared.dataTask(with: url) { data, response, error in + if let data = data { + if let string = String(data: data, encoding: .utf8) { + let lines = string.components(separatedBy: "\n") + for line in lines { + if email.contains(line) { + completion(true) + return + } + } + } + } + completion(false) + } + task.resume() +} +```