NetNewsWire/Evergreen/MainWindow/AddFeed/FeedTitleDownloader.swift

28 lines
596 B
Swift
Raw Normal View History

2017-05-27 19:43:27 +02:00
//
// FeedTitleDownloader.swift
// Evergreen
//
// Created by Brent Simmons on 9/3/16.
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
2017-05-27 19:43:27 +02:00
//
import Foundation
import RSParser
2017-05-27 19:43:27 +02:00
import RSWeb
func downloadTitleForFeed(_ url: URL, _ completionHandler: @escaping (_ title: String?) -> ()) {
download(url) { (data, response, error) in
guard let data = data else {
completionHandler(nil)
return
}
let parserData = ParserData(url: url.absoluteString, data: data)
FeedParser.parse(parserData) { (parsedFeed, error) in
2017-05-27 19:43:27 +02:00
completionHandler(parsedFeed?.title)
}
}
}