diff --git a/Widget/Shared Views/ArticleItemView.swift b/Widget/Shared Views/ArticleItemView.swift index ff922155e..a3fbebba9 100644 --- a/Widget/Shared Views/ArticleItemView.swift +++ b/Widget/Shared Views/ArticleItemView.swift @@ -13,14 +13,14 @@ struct ArticleItemView: View { var article: LatestArticle var deepLink: URL - @State private var iconImage: UIImage? + @State private var iconImage: Image? var body: some View { Link(destination: deepLink, label: { HStack(alignment: .top, spacing: nil, content: { // Feed Icon if iconImage != nil { - Image(uiImage: iconImage!) + iconImage! .resizable() .frame(width: 30, height: 30) .cornerRadius(4) @@ -49,16 +49,18 @@ struct ArticleItemView: View { } }) }).onAppear { - iconImage = thumbnail(article.feedIcon) + iconImage = thumbnail(from: article.feedIconPath) } } - func thumbnail(_ data: Data?) -> UIImage { - if data == nil { - return UIImage(systemName: "globe")! - } else { - return UIImage(data: data!)! + func thumbnail(from path: String?) -> Image? { + guard let imagePath = path, + let url = URL(string: imagePath), + let data = try? Data(contentsOf: url), + let uiImage = UIImage(data: data) else { + return Image(uiImage: UIImage(systemName: "globe")!) } + return Image(uiImage: uiImage) } func pubDate(_ dateString: String) -> String {