forked from lucxjo/leganto-apple
Louis Hollingworth
9345b91573
Added beginnings of feed parsing, may need to switch parser. Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
49 lines
1.2 KiB
Swift
49 lines
1.2 KiB
Swift
//
|
|
// 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()
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|