Skip to content

Instantly share code, notes, and snippets.

@nderkach
Created September 18, 2018 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nderkach/6b5009fef5327ea3ed6ca4851e895b71 to your computer and use it in GitHub Desktop.
Save nderkach/6b5009fef5327ea3ed6ca4851e895b71 to your computer and use it in GitHub Desktop.
static func fetchAndParseTrackerList(completion: @escaping (BlockerList) -> Void ) {
var parsedLines: [String] = []
// Fetch JSON file containing the list of trackers to block
Alamofire.request(Constants.trackerListURL).responseData { response in
if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {
let lines = utf8Text.components(separatedBy: .newlines)
for line in lines {
if line.starts(with: "#") || line.isEmpty {
continue
}
if let domainName = line.components(separatedBy: .whitespaces).first {
parsedLines.append(domainName)
}
}
completion(TrackerListParser.generateBlacklistJSON(from: parsedLines))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment