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 | |
precedencegroup LeftApplyPrecedence { | |
associativity: left | |
higherThan: AssignmentPrecedence | |
lowerThan: TernaryPrecedence | |
} | |
precedencegroup FunctionCompositionPrecedence { | |
associativity: 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
protocol CellWithIdentifier:class { | |
associatedtype T = Self | |
static var resuseIdentifier: String { get } | |
} | |
extension UICollectionViewCell:CellWithIdentifier { } | |
extension UITableViewCell:CellWithIdentifier { } | |
extension CellWithIdentifier { | |
static var resuseIdentifier: String { return String(self) } |
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 String { | |
var isHomogeneous:Bool { | |
let charSet = Set(self.characters) | |
return charSet.count == 0 || charSet.count == 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
// Need both of these, since one `adaptivePresentationStyleForPresentationController:` works on 8.0 to 8.2, and the other, | |
// `adaptivePresentationStyleForPresentationController:traitCollection:` works on 8.3 plus | |
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller { | |
return UIModalPresentationNone; | |
} | |
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection { | |
return UIModalPresentationNone; | |
} |
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
// this... | |
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) { | |
let group = data?[self.tableView.indexPathForSelectedRow().row] | |
if let destination = segue.destinationViewController as? ViewController { | |
destination.title = group?.valueForProperty(ALAssetsGroupPropertyName) as? NSString | |
destination.data = PhotoManager.lazySendableForGroup(manager) <^> group | |
} else { | |
println("Cast failed, proposed class of segue view controller is wrong") | |
} |
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 Cocoa | |
enum StringAttribute { | |
case List([StringAttribute]) | |
case Font(NSFont) | |
case BgColor(NSColor) | |
case FgColor(NSColor) | |
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
let userjs: NSData = "{\"name\": \"max\", \"age\": 10, \"tweets\": [\"hello\"], \"attrs\": {\"one\": \"1\", \"more\": {\"stuff\": \"again\"}}}" | |
.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) | |
let val = JSValue.decode(userjs) | |
let traversal = JSValue.key("attrs") • JSValue.key("more") • JSValue.key("stuff") | |
let getIt = traversal.get(val) | |
let setIt = traversal.set(val, JSValue.JSString("bob")) |
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
//this is a playground | |
struct Reader<R,A> { | |
let f:R -> A | |
init(_ fun:R -> A) { | |
f = fun | |
} | |
static func wrap(val:A) -> Reader<R,A> { | |
return Reader({_ in val}) |
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
operator infix <> { | |
associativity left | |
} | |
protocol Monoid { | |
typealias M | |
func mempty() -> M | |
func mappend(a:M) -> M | |
} |
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
//bind | |
operator infix >>= { | |
associativity left | |
} | |
struct Writer<A> { | |
let a:A | |
let s:String[] | |
init(_ a:A, _ s:String[]) { |
NewerOlder