Skip to content

Instantly share code, notes, and snippets.

View dmytro-anokhin's full-sized avatar
🔨

Dmytro Anokhin dmytro-anokhin

🔨
View GitHub Profile
struct ContentView: View {
@ObservedObject private var autocomplete = AutocompleteObject()
@State var input: String = ""
var body: some View {
VStack {
TextField("", text: $input)
.textFieldStyle(.roundedBorder)
@MainActor
final class AutocompleteObject: ObservableObject {
let delay: TimeInterval = 0.3
@Published var suggestions: [String] = []
init() {
}
extension CitiesCache {
func lookup(prefix: String) -> [String] {
cities.filter { $0.hasCaseAndDiacriticInsensitivePrefix(prefix) }
}
}
actor CitiesCache {
let source: CitiesSource
init(source: CitiesSource) {
self.source = source
}
var cities: [String] {
if let cities = cachedCities {
protocol CitiesSource {
func loadCities() -> [String]
}
struct CitiesFile: CitiesSource {
let location: URL
init(location: URL) {
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)
@dmytro-anokhin
dmytro-anokhin / GridView.swift
Created August 19, 2021 05:16
Simple grid for SwiftUI
//
// GridView.swift
// GridView
//
// Created by Dmytro Anokhin on 19/08/2021.
//
import SwiftUI
struct GridView: View {
//
// URLImageService+FetchImage.swift
//
// Created by Dmytro Anokhin on 09/01/2021.
//
import Foundation
import Combine
import URLImage
import SwiftUI
import Combine
import PlaygroundSupport
final class RemoteImage : ObservableObject {
enum LoadingState {
case initial
URLImageService.shared.cleanup() // Cleanup expired images
URLImageService.shared.defaultOptions.maxPixelSize = CGSize(width: 1000.0, height: 1000.0) // Limit image size to 1000x1000px