Skip to content

Instantly share code, notes, and snippets.

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

Matthias Tretter myell0w

๐Ÿ™Œ
View GitHub Profile
@kean
kean / cd_progressive_migration.m
Last active June 19, 2016 09:42
Tricking Core Data Into Performing Progressive Migrations
+ (BOOL)migrateStoreAtURL:(NSURL *)storeURL
models:(NSArray<NSManagedObjectModel *> *)moms // @[ mom_v1, mom_v2, mom_v3 ... ];
error:(NSError **)error {
// Find an index of the current store's mom
NSDictionary *meta = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType URL:storeURL error:error];
if (!meta) {
return NO;
}
NSInteger idx = [moms indexOfObjectPassingTest:^BOOL(NSManagedObjectModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
return [obj isConfiguration:nil compatibleWithStoreMetadata:meta];
@macguru
macguru / MXSEventTrackingWindow.h
Created September 2, 2016 10:47
Tell if a user interaction is currently happening though a touch event in a view's window or something else โ€“ย like an external keyboard or interaction in a different window (keyboard window). Example use: check if selection change was through touch or external keyboard.
//
// MXSEventTrackingWindow.h
//
// Created by Max Seelemann on 01.09.16.
// Copyright ยฉ 2016 The Soulmen. All rights reserved.
//
/*!
@abstract Special window class used for advanced event processing.
*/
@soffes
soffes / BaseTextStorage.swift
Last active July 1, 2023 10:14
Fast, concrete text storage intended to be subclassed.
import UIKit
/// Fast, concrete text storage intended to be subclassed.
class BaseTextStorage: NSTextStorage {
// MARK: - Properties
private let storage = NSMutableAttributedString()
// MARK: - NSTextStorage
@cocoaNib
cocoaNib / EssentialXcodeShortcuts
Last active November 28, 2016 10:52
Essential Xcode Shortcuts
Essential Xcode Shortcuts
๐Ÿ‡บ๐Ÿ‡ธ Keyboard
โŒ˜ B Build
โŒ˜ R Run
โŒ˜ U Run Test
โ‡ง โŒ˜ K Clean
โŒฅ โ‡ง โŒ˜ K Clean Build Folder
โ‡ง โŒ˜ O Open quickly
//
// LCKConcurrentOperation.m
// LCKOperations
//
// Created by Twig on 12/19/13.
// Copyright (c) 2013 Lickability. All rights reserved.
//
#import "LCKConcurrentOperation.h"
@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 {
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 / 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()
@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": ["๐Ÿถ", "๐Ÿฑ", "๐Ÿญ", "๐Ÿน", "๐Ÿฐ", "๐ŸฆŠ", "๐Ÿป", "๐Ÿผ", "๐Ÿจ", "๐Ÿฏ", "๐Ÿฆ", "๐Ÿฎ", "๐Ÿท", "๐Ÿฝ", "๐Ÿธ", "๐Ÿต", "๐Ÿ™ˆ", "๐Ÿ™‰", "๐Ÿ™Š", "๐Ÿ’", "๐Ÿ”", "๐Ÿง", "๐Ÿฆ", "๐Ÿค", "๐Ÿฃ", "๐Ÿฅ", "๐Ÿฆ†", "๐Ÿฆ…", "๐Ÿฆ‰", "๐Ÿฆ‡", "๐Ÿบ", "๐Ÿ—", "๐Ÿด", "๐Ÿฆ„", "๐Ÿ", "๐Ÿ›", "๐Ÿฆ‹", "๐ŸŒ", "๐Ÿš", "๐Ÿž", "๐Ÿœ", "๐Ÿ•ท", "๐Ÿ•ธ", "๐Ÿข", "๐Ÿ", "๐ŸฆŽ", "๐Ÿฆ‚", "๐Ÿฆ€", "๐Ÿฆ‘", "๐Ÿ™", "๐Ÿฆ", "๐Ÿ ", "๐ŸŸ", "๐Ÿก", "๐Ÿฌ", "๐Ÿฆˆ
@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 {