Skip to content

Instantly share code, notes, and snippets.

View shakemno's full-sized avatar

Manolis Pahlke shakemno

View GitHub Profile
@shakemno
shakemno / UILabel+Debug.swift
Created October 22, 2019 08:23 — forked from BjornRuud/UILabel+Debug.swift
Debug mode for UILabel that can optionally show bounds, ascender, descender, x height, cap height, baseline and leading.
import UIKit
struct UILabelDebugOptions: OptionSet {
let rawValue: Int
static let bounds = UILabelDebugOptions(rawValue: 1 << 0)
static let ascender = UILabelDebugOptions(rawValue: 1 << 1)
static let descender = UILabelDebugOptions(rawValue: 1 << 2)
static let xHeight = UILabelDebugOptions(rawValue: 1 << 3)
static let capHeight = UILabelDebugOptions(rawValue: 1 << 4)
@shakemno
shakemno / WorkUnitExecutor.swift
Created October 23, 2019 20:36 — forked from deze333/WorkUnitExecutor.swift
Multi-thread to single-thread synchronized executor pattern in Swift (playground)
// Multi to single thread execution
// Credits go to https://www.reddit.com/r/swift/comments/7ijbt0/whats_a_good_way_to_make_sync_calls_from_swift_to/dr4iwxr/
import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3000)) {
print("Done")
PlaygroundPage.current.finishExecution()
@shakemno
shakemno / 0. Reference
Created December 8, 2019 18:13 — forked from lamprosg/0. Reference
(iOS) SwiftUI tutorial
//https://www.hackingwithswift.com/quick-start/swiftui
@shakemno
shakemno / SwiftEventHandler.swift
Created December 8, 2019 18:14 — forked from lamprosg/SwiftEventHandler.swift
(iOS) Swift only KVO alternative, event handlers
//Documentation
//https://blog.scottlogic.com/2015/02/05/swift-events.html
//KVO example (not shown in this gist)
//https://blog.scottlogic.com/2015/02/11/swift-kvo-alternatives.html
public class Event<T> {
public typealias EventHandler = T -> ()
@shakemno
shakemno / gcd.swift
Created December 8, 2019 18:16 — forked from lamprosg/gcd.swift
(iOS) GCD
//https://medium.com/@nimjea/grand-central-dispatch-in-swift-fdfdd8b22d52
DispatchQueue.main.async {
// Perform your async code here
}
//Synced operations
let northZone = DispatchQueue(label: "perform_task_with_team_north")
//Sync operation
@shakemno
shakemno / AECoreData.swift
Created December 9, 2019 21:50 — forked from tadija/AECoreData.swift
AECoreData
/**
* https://gist.github.com/tadija/6003830264d67a87193ff0c3d20373e7
* Copyright (c) Marko Tadić 2018
* Licensed under the MIT license. See LICENSE file.
*/
import CoreData
extension NSFetchRequestResult where Self: NSManagedObject {
// MARK: Queries
@shakemno
shakemno / FRP iOS Learning resources.md
Created December 18, 2019 19:25 — forked from JaviLorbada/FRP iOS Learning resources.md
The best FRP iOS resources.

Videos

@shakemno
shakemno / Playground.swift
Created January 8, 2020 17:54 — forked from timdonnelly/Playground.swift
Maintaining visible scroll position while inserting items in a UICollectionView (Swift playground)
import Foundation
import UIKit
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
class Layout: UICollectionViewLayout {
private var attributes: [[UICollectionViewLayoutAttributes]] = []
@shakemno
shakemno / UIViewController+Helpers.swift
Last active February 24, 2020 15:21 — forked from Ankit-Aggarwal/UIViewController+Helpers
UIViewController Extension to handle keyboard updates easily
import Foundation
import UIKit
import ReactiveSwift
import Result
extension UIViewController {
typealias KeyboardStatusInfo = (height: CGFloat , duration: TimeInterval, animationOptions: UIViewAnimationOptions)
var keyboardUpdatesSignal: Signal<KeyboardStatusInfo, NoError> {
//------------------------------------------------------------------------
// The SwiftUI Lab: Advanced SwiftUI Animations
// https://swiftui-lab.com/swiftui-animations-part1 (Animating Paths)
// https://swiftui-lab.com/swiftui-animations-part2 (GeometryEffect)
// https://swiftui-lab.com/swiftui-animations-part3 (AnimatableModifier)
//------------------------------------------------------------------------
import SwiftUI
struct ContentView: View {