Skip to content

Instantly share code, notes, and snippets.

View stleamist's full-sized avatar

Dongkyu Kim (Max.kim) stleamist

View GitHub Profile
import Swift
extension CaseIterable where Self: Equatable {
var index: Self.AllCases.Index {
return Self.allCases.firstIndex(of: self)!
}
}
import Foundation
extension URL {
init?(string: String?) {
guard let string = string else {
return nil
}
self.init(string: string)
}
import Foundation
@propertyWrapper
public struct PercentEncodedURL: Codable {
public let wrappedValue: URL
public init(wrappedValue: URL) {
self.wrappedValue = wrappedValue
}
import Foundation
@propertyWrapper
public struct NullableURL: Codable {
public let wrappedValue: URL?
public init(wrappedValue: URL?) {
self.wrappedValue = wrappedValue
}
import Foundation
import Kingfisher
import FavIcon
struct KFFaviconProvider: ImageDataProvider {
let url: URL
let cacheKey: String
init(url: URL, cacheKey: String? = nil) {
import Foundation
import KeychainAccess
@propertyWrapper
struct KeychainStorage<Value: Codable> {
let key: String
let service: String
let initialValue: Value
import Disk
@propertyWrapper
struct File<Value: Codable> {
let path: String
let directory: Disk.Directory
let defaultValue: Value
init(_ path: String, directory: Disk.Directory, defaultValue: Value) {
self.path = path
import KingFisher
struct KFLinkPresentationIconProvider: ImageDataProvider {
let url: URL
let cacheKey: String
init(url: URL, cacheKey: String? = nil) {
self.url = url
self.cacheKey = cacheKey ?? url.absoluteString
import Combine
extension Publisher {
func printError() -> Publishers.HandleEvents<Self> {
return self.handleEvents(receiveCompletion: { completion in
if case .failure(let error) = completion {
Swift.print("receive error: \(error)")
}
})
}
@stleamist
stleamist / UnicodeURLDecodingEnabler.swift
Created June 15, 2020 12:24
A KeyedDecodingContainer extension that adds percent encoding to Unicode URL during Codable decoding process.
import Foundation
extension KeyedDecodingContainer {
func decode(_ type: URL.Type, forKey key: Key) throws -> URL {
do {
return try URL(from: superDecoder())
} catch (let error) {
guard
let urlString = try? decode(String.self, forKey: key),