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 ErrorType { | |
// MARK: - Internal functions | |
func describe() -> String { | |
if let error = self as? CustomStringConvertible { | |
return error.description | |
} else { | |
let error = self as NSError | |
return error.localizedDescription |
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
// From Tim Shadel | |
enum FakeError: String, ErrorType, CustomStringConvertible { | |
case LoginFailed | |
var description: String { | |
return "FakeError: \(self.rawValue)" | |
} | |
} |
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
// MARK: - HEX init | |
// From Tim Shadel | |
enum UIColorInputError: ErrorType { | |
case UnableToScanHexValue | |
} | |
extension UIColor { | |
convenience init(hex: Int, alpha: CGFloat = 1.0) { |
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
private func nearestPotentialStartTime(toTime time: NSDate) -> NSDate { | |
let calendar = NSCalendar.currentCalendar() | |
let components = calendar.components([.Era, .Year, .Month, .Day, .Hour, .Minute], fromDate: time) | |
let minutes = components.minute | |
let nextStartMark = (minutes % startInterval) + startInterval | |
let previousStartMark = nextStartMark - startInterval | |
let previousDelta = abs(minutes - previousStartMark) | |
let nextDelta = abs(minutes - nextStartMark) |
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 | |
class TextEditing: UIViewController { | |
@IBOutlet weak var textView: UITextView? | |
func updateText(with newString: String?) { | |
guard let textView = textView, newString = newString, (diffRange, changedText) = diff(textView.text, newString) else { return } | |
guard let selectedRange = textView.selectedTextRange else { textView.text = newString; return } | |
textView.text = newString |
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
collections: | |
drafts: | |
output: true |
OlderNewer