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 { | |
var firstResponder: UIView? { | |
if self.isFirstResponder() { | |
return self | |
} | |
for subview in self.subviews { | |
if let fr = subview.firstResponder /*as UIView? -- FIX */ { | |
assert(fr != nil, "THIS SHOULD NOT HAPPEN BUT DOES") | |
return fr |
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
//: Playground - noun: a place where people can play | |
import UIKit | |
protocol PlaceholderText : class, UITextInputTraits { | |
var placeholder: String? { get set } | |
} | |
extension UITextField: PlaceholderText { } | |
extension UITextView: PlaceholderText { |
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 Enum : Equatable { | |
case Case1 | |
case Case2(variable: AnyObject) | |
} | |
let a = Enum.Case1 | |
let b = a == Enum.Case1 | |
func == (e1: Enum, e2: Enum) -> Bool { | |
switch e1 { |
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 Nat: IntegerLiteralConvertible { | |
init(integerLiteral value: IntegerLiteralType) { | |
switch (value) { | |
case 0: | |
self = .Zero | |
default: | |
self = .Succ(Nat(integerLiteral: value - 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
// without double escapes: \A([^{}]*)(?:\{([^{}/]*)(?:\/([^{}/]*))+\})?([^{}]*)\z | |
let formatRegex = NSRegularExpression(pattern: "\\A([^{}]*)(?:\\{([^{}/]*)(?:/([^{}/]*))+\\})?([^{}]*)\\z", options: .allZeros, error: nil) | |
let test = "In this line {this should be captured/and this but it isn’t/and finally this}. I don’t understand." |
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
// Trying to write a function that does some select/map magic with easy error handling | |
let cities = [[ | |
"name": "Geneva", | |
"population": 184538 | |
],[ | |
"name": "Bern", | |
"population": 123154 | |
], [ | |
"name": "Zurich", |
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
@interface MyClass : NSObject | |
@property (nonatomic) BOOL boolProperty; | |
@end | |
@implementation MyClass | |
@end | |
// ... | |
MyClass* obj = [MyClass new]; |
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
protocol Delegate<T> { | |
func generate() -> T | |
} | |
class Controller<T> { | |
var delegate: Delegate<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
protocol TableControllerDelegate { | |
typealias ItemType | |
func tableViewCellForItem(item: ItemType, atIndexPath indexPath: NSIndexPath) -> UITableViewCell | |
} | |
class TableController<T> : NSObject, UITableViewDataSource, UITableViewDelegate { | |
var items: [T]? | |
var delegate: TableControllerDelegate? | |
//MARK: UITableViewDataSource & UITableViewDelegate Methods |
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/ruby | |
# | |
# update_storyboard_strings.rb - automatically extract translatable strings from storyboards and update strings files | |
# Based on: | |
# - http://forums.macrumors.com/showpost.php?p=16060008&postcount=4 by mikezang | |
# - http://oleb.net/blog/2013/02/automating-strings-extraction-from-storyboards-for-localization/ by Ole Begemann | |
require 'Tempfile' | |
Dir.glob('**/Base.lproj/*.storyboard') do |storyboard_path| |