leganto-apple/Leganto/FeedParser.swift

49 lines
1.2 KiB
Swift
Raw Permalink Normal View History

//
// FeedParser.swift
// Leganto
//
// Created by Louis Hollingworth on 2023-05-24.
//
import Foundation
import FeedKit
class LFeedParser: ObservableObject {
var urlStr: String
@Published var rssFeed: RSSFeed?
@Published var atomFeed: AtomFeed?
@Published var jsonFeed: JSONFeed?
init(urlStr: String) {
self.urlStr = urlStr
}
func loadData() {
if let url = URL(string: urlStr) {
let parser = FeedParser(URL: url)
parser.parseAsync { (result) in
switch result {
case .success(let feed):
switch feed {
case let .atom(feed):
self.atomFeed = feed
case let .json(feed):
self.jsonFeed = feed
case let .rss(feed):
self.rssFeed = feed
}
case .failure(let err):
print(err)
}
DispatchQueue.main.async {
self.objectWillChange.send()
}
}
}
}
}