Add Swift Code Example (#495)

* Add Swift Example

* Update README.md

Co-authored-by: Martin Cech <emulatorer@gmail.com>

---------

Co-authored-by: Martin Cech <emulatorer@gmail.com>
This commit is contained in:
MING 2024-09-24 16:41:01 +08:00 committed by GitHub
parent 80385d0d85
commit fb8b7bd1f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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()
}
```