mirror of
https://github.com/disposable-email-domains/disposable-email-domains.git
synced 2024-11-22 08:38:12 +08:00
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:
parent
80385d0d85
commit
fb8b7bd1f4
26
README.md
26
README.md
@ -35,7 +35,7 @@ Changelog
|
|||||||
Example Usage
|
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
|
||||||
```Python
|
```Python
|
||||||
@ -214,3 +214,27 @@ public static boolean isDisposable(InternetAddress contact) throws AddressExcept
|
|||||||
return DISPOSABLE_EMAIL_DOMAINS.contains(domain);
|
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()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user