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
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 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 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 | |
extension String { | |
func replaceCharactersFromSet(characterSet: NSCharacterSet, replacementString: String) -> String { | |
let scanner = NSScanner(string: self) | |
scanner.charactersToBeSkipped = nil | |
let sanitizedString = NSMutableString(capacity: self.characters.count) | |
while(!scanner.atEnd) { |
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
enum Fetched<T> { | |
case notFetched | |
case fetched(T) | |
} |
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
#!/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 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 UIKit | |
func namedModels() -> [ModelObject] { | |
let names: [String] = UIFont.familyNames() | |
return names.map(ModelObject.init) | |
} | |
class ModelObject: NSObject { | |
let name: String | |
init(name: String) { self.name = name } |
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/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 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 UIKit | |
protocol NibLoadable { | |
func setupFromXib() | |
} | |
// This extension loads a .xib file with the same filename as the class name | |
// i.e. `class FoobarHeaderView` -> loads FoobarHeaderView.xib | |
extension NibLoadable where Self: UIView { | |
func setupFromXib() { |
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
// | |
// KeyboardInsettable.swift | |
// | |
// Created by Josh Avant on 9/11/18. | |
// | |
import Foundation | |
import UIKit | |
protocol KeyboardInsettable { |
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 | |
enum Result<T,U> { | |
case firstType(T) | |
case secondType(U) | |
} | |
enum Validation<T,Error> { | |
case valid(T) | |
case invalid(Error) |
NewerOlder