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
func calculateTextViewHeight(inset: UIEdgeInsets, lineFragmentPadding: CGFloat = 5.0, maxWidth: CGFloat, text: String, font: UIFont) -> CGSize { | |
let widthWithoutInset = maxWidth - (inset.left + inset.right + (2 * lineFragmentPadding)) | |
let contraintRect = CGSize(width: widthWithoutInset, height: CGFloat.max) | |
let style = NSMutableParagraphStyle() | |
style.lineBreakMode = .ByWordWrapping | |
let attributes = [NSFontAttributeName: font, NSParagraphStyleAttributeName: style] | |
let boudingBox = NSString(string: text).boundingRectWithSize(contraintRect, options: .UsesLineFragmentOrigin, attributes: attributes, context: nil) | |
let newWidth = (boudingBox.size.width + (inset.left + inset.right + (2 * lineFragmentPadding) + 0.25)).roundNearest(0.5) | |
let newHeight = (boudingBox.size.height + ((inset.top + inset.bottom) + 0.25)).roundNearest(0.5) | |
return CGSize(width: newWidth, height: newHeight) |
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 String { | |
func height(withConstrainedWidth width: CGFloat, font: UIFont) -> CGFloat { | |
let constraintRect = CGSize(width: width, height: .greatestFiniteMagnitude) | |
let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil) | |
return boundingBox.height | |
} | |
} |
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 UIKit | |
import AVFoundation | |
import Photos | |
class ViewController: UIViewController { | |
var focusMarker: UIImageView! | |
var exposureMarker: UIImageView! | |
var resetMarker: UIImageView! | |
private var adjustingExposureContext: String = "" |
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
class AsyncOperation: Operation { | |
enum State: String { | |
case Ready, Executing, Finished | |
fileprivate var keyPath: String { | |
return "is" + rawValue | |
} | |
} | |
var state = State.Ready { | |
willSet { |
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
# Git branch in prompt. | |
parse_git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | |
} | |
export PS1="\u@\h \[\033[32m\]\w\[\e[91m\]\$(parse_git_branch)\[\033[00m\] $ " |
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
//: Playground - noun: a place where people can play | |
import UIKit | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
let userQueue = DispatchQueue.global(qos: .userInitiated) | |
let defaultQueue = DispatchQueue.global() |
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 | |
import Alamofire | |
enum NetworkStatus { | |
case WWAN | |
case EthernetOrWiFi | |
case NotReachable | |
case Unknown | |
} |
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
protocol GeneratorType { | |
associatedtype Element | |
mutating func next() -> Element? | |
} | |
class FibsGenerator: GeneratorType { | |
var state = (0, 1) | |
func next() -> Int? { | |
let upcomingNumber = state.0 | |
state = (state.1, state.0 + state.1) |
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 AVAsset { | |
func videoOrientation() -> (orientation: UIInterfaceOrientation, device: AVCaptureDevicePosition) { | |
var orientation: UIInterfaceOrientation = .Unknown | |
var device: AVCaptureDevicePosition = .Unspecified | |
let tracks :[AVAssetTrack] = self.tracksWithMediaType(AVMediaTypeVideo) | |
if let videoTrack = tracks.first { | |
let t = videoTrack.preferredTransform |