Skip to content

Instantly share code, notes, and snippets.

View kingnight's full-sized avatar
🎯
Focusing

jinkai kingnight

🎯
Focusing
View GitHub Profile
@lukebrandonfarrell
lukebrandonfarrell / ExifData.swift
Created June 8, 2022 16:10
A Swift class for extracting exif data from URL, UIImage or Data types 🔭
//
// ExifData.swift
// Qeepsake
//
// Created by Luke Farrell on 26/05/2022.
//
import Foundation
import ImageIO
@kingnight
kingnight / xcframework_realm.sh
Created May 15, 2022 08:42 — forked from leemaguire/xcframework_realm.sh
Remove naming collisions in swiftinterface. Run this script in the root of the RealmSwift.xcframework folder
#!/bin/bash
set -o pipefail
set -e
find . -name "*.swiftinterface" -exec sed -i -e 's/Realm\.//g' {} \;
find . -name "*.swiftinterface" -exec sed -i -e 's/import Private/import Realm.Private/g' {} \;
find . -name "*.swiftinterface" -exec sed -i -e 's/RealmSwift.Configuration/RealmSwift.Realm.Configuration/g' {} \;
find . -name "*.swiftinterface" -exec sed -i -e 's/extension Configuration/extension Realm.Configuration/g' {} \;
find . -name "*.swiftinterface" -exec sed -i -e 's/RealmSwift.Error/RealmSwift.Realm.Error/g' {} \;
find . -name "*.swiftinterface" -exec sed -i -e 's/extension Error/extension Realm.Error/g' {} \;
@onevcat
onevcat / Default.swift
Created November 10, 2020 03:56
Sample code of using Default to decode a property to the default value
import UIKit
protocol DefaultValue {
associatedtype Value: Decodable
static var defaultValue: Value { get }
}
@propertyWrapper
struct Default<T: DefaultValue> {
var wrappedValue: T.Value
@mjm
mjm / Observables.swift
Created July 3, 2020 13:50
StateObject vs. ObservableObject
// If you run this in a playground in Xcode 12, you can see the difference in behavior in the live view.
import SwiftUI
import PlaygroundSupport
class Counter: ObservableObject {
@Published var count: Int
init(_ initialCount: Int) {
self.count = initialCount
import Foundation
import Combine
protocol Resumable {
func resume()
}
extension Subscribers {
class ResumableSink<Input, Failure: Error>: Subscriber, Cancellable, Resumable {
let receiveCompletion: (Subscribers.Completion<Failure>) -> Void
import Foundation
extension Character {
var isEmoji: Bool {
return unicodeScalars.allSatisfy { $0.properties.isEmoji }
}
}
func recentlyUsedEmoji() -> [Character]? {
#if os(iOS)
@bardonadam
bardonadam / DynamicColor.swift
Last active August 20, 2021 03:22
DynamicColor property wrapper type to remove boilerplate code when defining dynamic colors to adopt dark mode on iOS 13
@DynamicColor(lightVariant: .black, darkVariant: .white)
static var dynamicLabelColor: UIColor
@propertyWrapper
struct DynamicColor {
let lightVariant: UIColor
let darkVariant: UIColor
var wrappedValue: UIColor {
get {
// orogin swift protocol and calling
protocol aProtocol {
func testFunc()
}
class aStruct: aProtocol {
func testFunc() {} // override defualt implementation
}
class bStruct: aProtocol {
func testFunc() {} // override defualt implementation
}
@oliveratgithub
oliveratgithub / emojis.json
Last active April 26, 2024 22:35
Emoji-list with emojis, names, shortcodes, unicode and html entities [massive list]
{
"emojis": [
{"emoji": "👩‍👩‍👧‍👧", "name": "family: woman, woman, girl, girl", "shortname": ":woman_woman_girl_girl:", "unicode": "1F469 200D 1F469 200D 1F467 200D 1F467", "html": "&#128105;&zwj;&#128105;&zwj;&#128103;&zwj;&#128103;", "category": "People & Body (family)", "order": ""},
{"emoji": "👩‍👩‍👧‍👦", "name": "family: woman, woman, girl, boy", "shortname": ":woman_woman_girl_boy:", "unicode": "1F469 200D 1F469 200D 1F467 200D 1F466", "html": "&#128105;&zwj;&#128105;&zwj;&#128103;&zwj;&#128102;", "category": "People & Body (family)", "order": ""},
{"emoji": "👩‍👩‍👦‍👦", "name": "family: woman, woman, boy, boy", "shortname": ":woman_woman_boy_boy:", "unicode": "1F469 200D 1F469 200D 1F466 200D 1F466", "html": "&#128105;&zwj;&#128105;&zwj;&#128102;&zwj;&#128102;", "category": "People & Body (family)", "order": ""},
{"emoji": "👨‍👩‍👧‍👧", "name": "family: man, woman, girl, girl", "shortname": ":man_woman_girl_girl:", "unicode": "1F468 200D 1F469 200D 1F467 200D 1F467", "html": "&#128104;&zwj;&#128105;&z
@gbammc
gbammc / StateMachine.swift
Created October 3, 2017 03:08
StateMachine
import Foundation
protocol StateType: Hashable {}
protocol EventType: Hashable {}
struct Transition<S: StateType, E: EventType> {
let event: E
let fromState: S
let toState: S