Skip to content

Instantly share code, notes, and snippets.

View myell0w's full-sized avatar
๐Ÿ™Œ

Matthias Tretter myell0w

๐Ÿ™Œ
View GitHub Profile
@defagos
defagos / BodyCounter.swift
Last active December 13, 2022 16:07
Decorate the view with a bordered debugging frame whose attached label displays how many times the view body has been evaluated.
import SwiftUI
import UIKit
private struct BodyCounterView: UIViewRepresentable {
let color: UIColor
private let id = UUID() // Force view updates
func makeUIView(context: Context) -> _BodyCounterView {
let view = _BodyCounterView()
@simonbs
simonbs / KeyboardAvoidingView.swift
Created January 24, 2022 21:29
Avoid undocked keyboard at bottom.
// Sample code made in response to this tweet:
// https://twitter.com/stroughtonsmith/status/1485719749673820163
final class MainView: UIView {
private let textView: UITextView = {
let this = UITextView()
this.translatesAutoresizingMaskIntoConstraints = false
this.text = "I'm a text view"
this.font = .preferredFont(forTextStyle: .body)
this.textColor = .label
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, DBGInterfaceStyleOverride) {
DBGInterfaceStyleOverrideNone = 0,
DBGInterfaceStyleOverrideLight,
DBGInterfaceStyleOverrideDark,
};
#ifdef __cplusplus
extern "C" {
@IanKeen
IanKeen / Redraw.swift
Last active February 28, 2023 21:20
PropertyWrapper: Automatically redraw UIViews when a value changes
@propertyWrapper
struct Redraw<Value> {
var wrappedValue: Value
init(wrappedValue: Value) {
self.wrappedValue = wrappedValue
}
static subscript<Instance: UIView>(
_enclosingInstance instance: Instance,
@steventroughtonsmith
steventroughtonsmith / UIView+Tooltips.h
Last active December 23, 2023 11:05
WIP tooltips for Mac Catalyst
//
// UIView+Tooltips.h
// Crossword
//
// Created by Steven Troughton-Smith on 13/09/2019.
// Copyright ยฉ 2019 Steven Troughton-Smith. All rights reserved.
//
#import <UIKit/UIKit.h>
@frankrausch
frankrausch / String+Hyphenation.swift
Last active June 15, 2023 16:45
Returns a String with soft hyphens (U+00AD)
import Foundation
extension String {
func hyphenated(languageCode: String) -> String {
let locale = Locale(identifier: languageCode)
return self.hyphenated(locale: locale)
}
func hyphenated(locale: Locale) -> String {
@zats
zats / emojis.swift
Created September 17, 2017 18:24
All emojis available in iOS 11.0 including lookup categories for gender and skin-tone dependent
let emojis: [String: [String]] = [
// +[EMFEmojiCategory TravelAndPlacesEmoji]
"travel": ["๐Ÿš—", "๐Ÿš•", "๐Ÿš™", "๐ŸšŒ", "๐ŸšŽ", "๐ŸŽ", "๐Ÿš“", "๐Ÿš‘", "๐Ÿš’", "๐Ÿš", "๐Ÿšš", "๐Ÿš›", "๐Ÿšœ", "๐Ÿ›ด", "๐Ÿšฒ", "๐Ÿ›ต", "๐Ÿ", "๐Ÿšจ", "๐Ÿš”", "๐Ÿš", "๐Ÿš˜", "๐Ÿš–", "๐Ÿšก", "๐Ÿš ", "๐ŸšŸ", "๐Ÿšƒ", "๐Ÿš‹", "๐Ÿšž", "๐Ÿš", "๐Ÿš„", "๐Ÿš…", "๐Ÿšˆ", "๐Ÿš‚", "๐Ÿš†", "๐Ÿš‡", "๐ŸšŠ", "๐Ÿš‰", "๐Ÿš", "๐Ÿ›ฉ", "โœˆ๏ธ", "๐Ÿ›ซ", "๐Ÿ›ฌ", "๐Ÿš€", "๐Ÿ›ฐ", "๐Ÿ’บ", "๐Ÿ›ถ", "โ›ต๏ธ", "๐Ÿ›ฅ", "๐Ÿšค", "๐Ÿ›ณ", "โ›ด", "๐Ÿšข", "โš“๏ธ", "๐Ÿšง", "โ›ฝ๏ธ", "๐Ÿš", "๐Ÿšฆ", "๐Ÿšฅ", "๐Ÿ—บ", "๐Ÿ—ฟ", "๐Ÿ—ฝ", "โ›ฒ๏ธ", "๐Ÿ—ผ", "๐Ÿฐ", "๐Ÿฏ", "๐ŸŸ", "๐ŸŽก", "๐ŸŽข", "๐ŸŽ ", "โ›ฑ", "๐Ÿ–", "๐Ÿ", "โ›ฐ", "๐Ÿ”", "๐Ÿ—ป", "๐ŸŒ‹", "๐Ÿœ", "๐Ÿ•", "โ›บ๏ธ", "๐Ÿ›ค", "๐Ÿ›ฃ", "๐Ÿ—", "๐Ÿญ", "๐Ÿ ", "๐Ÿก", "๐Ÿ˜", "๐Ÿš", "๐Ÿข", "๐Ÿฌ", "๐Ÿฃ", "๐Ÿค", "๐Ÿฅ", "๐Ÿฆ", "๐Ÿจ", "๐Ÿช", "๐Ÿซ", "๐Ÿฉ", "๐Ÿ’’", "๐Ÿ›", "โ›ช๏ธ", "๐Ÿ•Œ", "๐Ÿ•", "๐Ÿ•‹", "โ›ฉ", "๐Ÿ—พ", "๐ŸŽ‘", "๐Ÿž", "๐ŸŒ…", "๐ŸŒ„", "๐ŸŒ ", "๐ŸŽ‡", "๐ŸŽ†", "๐ŸŒ‡", "๐ŸŒ†", "๐Ÿ™", "๐ŸŒƒ", "๐ŸŒŒ", "๐ŸŒ‰", "๐ŸŒ"],
// +[EMFEmojiCategory NatureEmoji]
"nature": ["๐Ÿถ", "๐Ÿฑ", "๐Ÿญ", "๐Ÿน", "๐Ÿฐ", "๐ŸฆŠ", "๐Ÿป", "๐Ÿผ", "๐Ÿจ", "๐Ÿฏ", "๐Ÿฆ", "๐Ÿฎ", "๐Ÿท", "๐Ÿฝ", "๐Ÿธ", "๐Ÿต", "๐Ÿ™ˆ", "๐Ÿ™‰", "๐Ÿ™Š", "๐Ÿ’", "๐Ÿ”", "๐Ÿง", "๐Ÿฆ", "๐Ÿค", "๐Ÿฃ", "๐Ÿฅ", "๐Ÿฆ†", "๐Ÿฆ…", "๐Ÿฆ‰", "๐Ÿฆ‡", "๐Ÿบ", "๐Ÿ—", "๐Ÿด", "๐Ÿฆ„", "๐Ÿ", "๐Ÿ›", "๐Ÿฆ‹", "๐ŸŒ", "๐Ÿš", "๐Ÿž", "๐Ÿœ", "๐Ÿ•ท", "๐Ÿ•ธ", "๐Ÿข", "๐Ÿ", "๐ŸฆŽ", "๐Ÿฆ‚", "๐Ÿฆ€", "๐Ÿฆ‘", "๐Ÿ™", "๐Ÿฆ", "๐Ÿ ", "๐ŸŸ", "๐Ÿก", "๐Ÿฌ", "๐Ÿฆˆ
@chriseidhof
chriseidhof / scanner.swift
Last active February 6, 2019 14:10
Scanning Sequences
import Foundation
// Alternatives to `Scanner` (before: `NSScanner`).
// A scanner only needs a way to peek and to move to the next token.
protocol ScannerProtocol {
associatedtype Token: Equatable
var peek: Token? { get }
mutating func moveToNextToken()
import Foundation
final class Sample: NSObject {
@objc dynamic var name: String = ""
}
class MyObj: NSObject {
@objc dynamic var test: String = ""
}
extension NSObjectProtocol where Self: NSObject {
@chriseidhof
chriseidhof / sample.swift
Last active December 6, 2019 22:52
Observable References
import Foundation
// A lens is a getter and a setter combined
struct Lens<Whole, Part> {
let get: (Whole) -> Part
let set: (inout Whole, Part) -> ()
}
// We can create a lens from a key path
extension Lens {