Created
September 18, 2018 10:19
-
-
Save nderkach/6b5009fef5327ea3ed6ca4851e895b71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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