This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct ContentView: View { | |
| @ObservedObject private var autocomplete = AutocompleteObject() | |
| @State var input: String = "" | |
| var body: some View { | |
| VStack { | |
| TextField("", text: $input) | |
| .textFieldStyle(.roundedBorder) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @MainActor | |
| final class AutocompleteObject: ObservableObject { | |
| let delay: TimeInterval = 0.3 | |
| @Published var suggestions: [String] = [] | |
| init() { | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension CitiesCache { | |
| func lookup(prefix: String) -> [String] { | |
| cities.filter { $0.hasCaseAndDiacriticInsensitivePrefix(prefix) } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| actor CitiesCache { | |
| let source: CitiesSource | |
| init(source: CitiesSource) { | |
| self.source = source | |
| } | |
| var cities: [String] { | |
| if let cities = cachedCities { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol CitiesSource { | |
| func loadCities() -> [String] | |
| } | |
| struct CitiesFile: CitiesSource { | |
| let location: URL | |
| init(location: URL) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct ContentView: View { | |
| private var suggestions = ["Amstelveen", "Amsterdam", "Amsterdam-Zuidoost", "Amstetten"] | |
| @State var input: String = "" | |
| var body: some View { | |
| VStack { | |
| TextField("", text: $input) | |
| .textFieldStyle(.roundedBorder) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // GridView.swift | |
| // GridView | |
| // | |
| // Created by Dmytro Anokhin on 19/08/2021. | |
| // | |
| import SwiftUI | |
| struct GridView: View { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // URLImageService+FetchImage.swift | |
| // | |
| // Created by Dmytro Anokhin on 09/01/2021. | |
| // | |
| import Foundation | |
| import Combine | |
| import URLImage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| import Combine | |
| import PlaygroundSupport | |
| final class RemoteImage : ObservableObject { | |
| enum LoadingState { | |
| case initial |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| URLImageService.shared.cleanup() // Cleanup expired images | |
| URLImageService.shared.defaultOptions.maxPixelSize = CGSize(width: 1000.0, height: 1000.0) // Limit image size to 1000x1000px |
NewerOlder