Skip to content

Instantly share code, notes, and snippets.

View zats's full-sized avatar

Sash Zats zats

View GitHub Profile
class Parent {
var child: Child? {
didSet {
child.callback = weak(self)?.delegateCallback
}
}
func delegateCallback() {
// ...
@zats
zats / Problem.swift
Last active November 4, 2021 08:40
Recursive structures in Swift without Box classes
struct Node<T> { // error: recursive value type 'Node<T>' is not allowed
var child: Node?
var value: T
init(value: T, child: Node? = nil) {
self.value = value
self.child = child
}
}
@zats
zats / pubsub.swift
Last active May 26, 2016 21:16
PubSub protocol
protocol PubSubMessageType {
associatedtype Topic
var topic: Topic { get }
}
protocol PubSubType {
associatedtype Message = PubSubMessageType
associatedtype Topic
@zats
zats / usage.swift
Created July 16, 2016 06:01
Optional escape operator
// flow controll using do-catch
do {
try commentBody(¿commentRangeBeforeOffset(¿getNameOffset(dictionary)))
} catch let e as OptionalError {
} catch {
}
// folding into optional value. Currently produces double optional
@zats
zats / Podfile
Last active July 20, 2016 22:55
target '…' do
end
post_install do |installer_or_rep|
installer = installer_or_rep.respond_to?(:installer) ? installer_or_rep.installer : installer_or_rep
installer.pods_project.build_configurations.each do |config|
# Only in debug
if config.name.include?("Debug")
@zats
zats / Models.swift
Last active August 10, 2017 19:49 — forked from JaviSoto/SampleViewController.swift
Init based Storyboard View Controller Instantiation
import Foundation
// Some clearly non-NSObject-based models:
enum Coconut: String {
case small, medium, large
}
struct Tomato {
static var red = Tomato(color: #colorLiteral(red: 0.7490196078, green: 0.09803921569, blue: 0.02352941176, alpha: 1))
@zats
zats / File.swift
Last active January 9, 2017 05:11
Kill compiler with this one weird trick
import UIKit
class ViewController: UIViewController {
private var a1: Int!
private var a2: Int!
private var a3: Int!
private var a4: Int!
private var a5: Int!
private var a6: Int!
@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": ["🐶", "🐱", "🐭", "🐹", "🐰", "🦊", "🐻", "🐼", "🐨", "🐯", "🦁", "🐮", "🐷", "🐽", "🐸", "🐵", "🙈", "🙉", "🙊", "🐒", "🐔", "🐧", "🐦", "🐤", "🐣", "🐥", "🦆", "🦅", "🦉", "🦇", "🐺", "🐗", "🐴", "🦄", "🐝", "🐛", "🦋", "🐌", "🐚", "🐞", "🐜", "🕷", "🕸", "🐢", "🐍", "🦎", "🦂", "🦀", "🦑", "🐙", "🦐", "🐠", "🐟", "🐡", "🐬", "🦈
@zats
zats / FindReplace.json
Last active May 5, 2025 17:54
Alternative spellings for some emojis according to /System/Library/PrivateFrameworks/CoreEmoji.framework/Versions/A/Resources/en.lproj/FindReplace.strings
{
"💍":"diamond | engagement ring | diamond ring | diamond rings | diamonds | engagement rings",
"🆎":"blood type AB",
"❣":"heart",
"🇱🇨":"Saint Lucia | Saint Lucian flag",
"🇮🇪":"Ireland | Irish flag",
"🇨🇮":"Côte d’Ivoire | Ivory Coast | Ivorian flag",
"💎":"diamond | gem | gemstone | jewel | diamonds | gems | gemstones | jewels",
"☠️":"skull and crossbones | poison | poisonous",
"👩‍💻":"technology worker | tech worker | technologist | techie | IT worker | Apple genius | woman in technology | woman tech worker | woman technologist | woman IT worker | woman in IT | woman Apple genius",
@zats
zats / 0_usage.mm
Last active September 16, 2019 16:19
Load private framework, core service, app, etc
void *handler = loadPrivate(@"ChatKit", TypePrivateFramework);
const Class CKGradientViewCls = NSClassFromString(@"CKGradientView");
UIView *const gradientView = [(UIView *)[CKGradientViewCls alloc] initWithFrame:{0, 0, 300, 200}];