This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/swift | |
/// Args: | |
/// --xcode {XCODE_PATH} | |
import Foundation | |
extension Array { | |
func paired() -> [(Element, Element)] { | |
return stride(from: 0, to: count - 1, by: 2).map { | |
(self[$0], self[$0 + 1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Result | |
public extension Result { | |
/// Constructs a success wrapping `value`, iff `value` is not nil and `error` is nil. | |
/// | |
/// Constructs a failure wrapping `error`, iff `error` is not nil and `value` is nil. | |
/// | |
/// Otherwise, returns nil. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: Compose | |
func compose<A,B,C>(_ f: @escaping (B) -> C, after g: @escaping (A) -> B) -> ((A) -> C) { | |
return { f(g($0)) } | |
} | |
// MARK: Functor | |
/// The FunctorType protocol is used for types that can be mapped over. Types conforming to | |
/// FunctorType must implement a Functor constructor which must satisfy the following laws: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CDZIdioms.h | |
// https://www.dzombak.com/blog/2015/02/Tiny-Swift-idioms-in-ObjC.html | |
// | |
// Created by Chris Dzombak on 3/21/15. | |
// Copyright (c) 2015 Chris Dzombak. All rights reserved. | |
// | |
#ifndef CDZIdioms_h | |
#define CDZIdioms_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Person.swift | |
struct Person { | |
let givenName: String | |
let familyName: String | |
} | |
// SecretAgent.swift | |
protocol SecretAgent { | |
var givenName: String { get } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Key-Value Observing of NSUserDefaults.standardUserDefaults is unsafe. | |
Do not KVO the standardUserDefaults because an invocation of resetStandardUserDefaults() | |
anywhere in the codebase causes that KVO to silently stop observing. The comment of | |
resetStandardUserDefaults() in NSUserDefaults.h (below) states this behavior, but I'd | |
have found the comment more clear had it pointed out that the behavior makes | |
standardUserDefaults unfit for Key-Value Observation. | |
> The only visible effect this has is that all KVO observers of the previous |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIView+RecursiveDescription.swift | |
// | |
// Created by Logan Moseley on 12/11/15. | |
// | |
import UIKit | |
extension UIView { | |
var recursiveDescription: String { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iPhone 6.0 Simulator | |
(lldb) po self.collectionView | |
(PSTCollectionView *) $1 = 0x12a13a00 <UICollectionView: 0x12a13a00; frame = (0 0; 320 431); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x1216de90>; layer = <CALayer: 0x1216db60>; contentOffset: {0, -64}> collection view layout: <PSUICollectionViewFlowLayout_: 0x12173d00> | |
(lldb) p (UIEdgeInsets) [self.collectionView contentInset] | |
(UIEdgeInsets) $2 = { | |
(CGFloat) top = 64 | |
(CGFloat) left = 0 | |
(CGFloat) bottom = 0 |
NewerOlder