This file contains hidden or 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
enum Fetched<T> { | |
case notFetched | |
case fetched(T) | |
} |
This file contains hidden or 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/env bash | |
project=.; | |
objc=`grep -r "^@implementation " $project | wc -l | tr -d ' '`; | |
swift=`grep -r "^class " $project | wc -l | tr -d ' '`; | |
ratio=$(bc <<< "scale=3; $swift / $objc"); | |
ratio_perc=$(bc <<< "$ratio * 100"); | |
echo "Swift classes: $swift"; |
This file contains hidden or 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
extension UIView { | |
@objc func exerciseAmbiguityInLayoutRepeatedly() { | |
if self.hasAmbiguousLayout { | |
Timer.scheduledTimer(timeInterval: 0.5, | |
target: self, | |
selector: #selector(UIView.exerciseAmbiguityInLayout), | |
userInfo: nil, | |
repeats: true) | |
} | |
} |
This file contains hidden or 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
// | |
// KeyboardInsettable.swift | |
// | |
// Created by Josh Avant on 9/11/18. | |
// | |
import Foundation | |
import UIKit | |
protocol KeyboardInsettable { |
This file contains hidden or 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
#!/bin/bash | |
if [ "$EUID" -ne 0 ] | |
then echo "Please run as root" | |
exit | |
fi | |
echo "Killing VDCAssistant..." | |
sudo killall VDCAssistant | |
echo "Killing AppleCameraAssistant..." |
This file contains hidden or 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 | |
enum Result<T,U> { | |
case firstType(T) | |
case secondType(U) | |
} | |
enum Validation<T,Error> { | |
case valid(T) | |
case invalid(Error) |
This file contains hidden or 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
enum BirthdateValidation { | |
case valid(Date) | |
case missingComponents(Set<Birthdate.Component>) | |
case notOldEnough | |
init(date: Birthdate?) { | |
// implement validation for all states | |
} | |
} |
This file contains hidden or 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
extension UITextView { | |
// Note: This will trigger a text rendering! | |
func calculateViewHeightWithCurrentWidth() -> CGFloat { | |
let textWidth = self.frame.width - | |
self.textContainerInset.left - | |
self.textContainerInset.right - | |
self.textContainer.lineFragmentPadding * 2.0 - | |
self.contentInset.left - | |
self.contentInset.right | |
This file contains hidden or 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
(lldb) po self.tableView.visibleCells | |
0 elements | |
(lldb) po self.tableView.indexPathsForVisibleRows | |
▿ Optional<Array<NSIndexPath>> | |
▿ Some : 3 elements | |
- [0] : <NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0} | |
- [1] : <NSIndexPath: 0xc000000000200016> {length = 2, path = 0 - 1} | |
- [2] : <NSIndexPath: 0xc000000000400016> {length = 2, path = 0 - 2} |
This file contains hidden or 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
if context == &FooKVOContext { | |
// .CGSizeValue can cause a sneaky segfault here, because it will execute on ALL keyPaths (not just "contentSize") | |
if let newContentSize = change?[NSKeyValueChangeNewKey]?.CGSizeValue() where keyPath == "contentSize" { | |
// do things | |
} | |
} else { | |
super.observeValueForKeyPath(keyPath, ofObject: object, change: change, context: context) | |
} |
NewerOlder