From 340325fa9aa4ff2c3c9669bf6391759c85b7d8a7 Mon Sep 17 00:00:00 2001 From: thoamsy Date: Sat, 21 Nov 2020 12:24:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=8D=A2=E6=8E=A5=E5=8F=A3=E7=9A=84?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Shared/ContentView.swift | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Shared/ContentView.swift b/Shared/ContentView.swift index 0fcd1d1..ef80c01 100644 --- a/Shared/ContentView.swift +++ b/Shared/ContentView.swift @@ -5,14 +5,19 @@ import Combine struct SFIcons: Codable { let version: Float - let `public`: [String] + let icons: [String] } class SFIconsList: ObservableObject { let requestURL = URL(string: "https://raw.githubusercontent.com/thoamsy/sf-icon-names/master/sf-name.json")! - @Published var icons: [String] = [] + @Published var icons: [String] = [] { + didSet { + fetching = false + } + } + @Published var fetching = false init() { start() @@ -22,11 +27,12 @@ class SFIconsList: ObservableObject { func start() { publisher?.cancel() + self.fetching = true publisher = URLSession.shared .dataTaskPublisher(for: requestURL) .map(\.data) .decode(type: SFIcons.self, decoder: JSONDecoder()) - .map(\.public) + .map(\.icons) .retry(2) .replaceError(with: []) .eraseToAnyPublisher() @@ -46,7 +52,7 @@ struct ContentView: View { var body: some View { return VStack { - if sfIcons.icons.isEmpty { + if sfIcons.fetching { ProgressView() } else { ScrollView { @@ -64,6 +70,7 @@ struct ContentView: View { .background(index == selectedIndex ? Color(UIColor.link) : Color(UIColor.secondarySystemGroupedBackground)) } .font(.title2) + .padding() } } }