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 | |
extension UISegmentedControl { | |
func goVertical() { | |
self.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2)) | |
for segment in self.subviews { | |
for segmentSubview in segment.subviews { | |
if segmentSubview is UILabel { | |
(segmentSubview as UILabel).transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_2)) | |
} |
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 DeselectableSegmentedControl: UISegmentedControl { | |
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) { | |
let previouslySelectedIndex = self.selectedSegmentIndex | |
super.touchesEnded(touches, withEvent: event) | |
if previouslySelectedIndex == self.selectedSegmentIndex { | |
self.selectedSegmentIndex = UISegmentedControlNoSegment | |
self.sendActionsForControlEvents(UIControlEvents.ValueChanged) | |
} |
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
// CaseInsensitiveDictionary.swift | |
// Created by Daniel Duan on 12/19/14. | |
// Usaege Example: | |
// var test = CaseInsensitiveDictionary<String, Int>() | |
// test["Winter is coming"] = 1 | |
// | |
// test["WINTER is Coming"] = test["Winter Is Coming"] // true | |
// test["Hear Our Roar?"] = 1 | |
// | |
// test.count == 2 // true |
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
struct Complex<T: FloatLiteralConvertible> { | |
var real: T | |
var imaginary: T | |
} | |
func +(lhs: Complex<Double>, rhs: Complex<Double>) -> Complex<Double> { | |
return Complex<Double>(real: lhs.real + rhs.real, imaginary: lhs.imaginary + rhs.imaginary) | |
} | |
func -(lhs: Complex<Double>, rhs: Complex<Double>) -> Complex<Double> { |
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
#!/usr/bin/env xcrun swift | |
/* | |
usage: | |
1. chmod +x QuickOutline.swift | |
2. ./QuickOutline.swift outline.json | |
this will generate BDD/[Quick](https://github.com/Quick/Quick) style test outlines according to outline.json | |
an example outline.json: |
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
// Swift 2 Beta 2 to the rescue! | |
protocol A { | |
var b: B { get set } | |
} | |
protocol B { | |
func handle() | |
} | |
extension B { |
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
SDKPATH = $(shell xcrun --show-sdk-path --sdk macosx) | |
CBRIDGEHEADER = bridge.h | |
TARGETS := cat | |
.PHONY : all $(TARGETS) | |
all: $(TARGETS) | |
$(TARGETS): | |
swiftc -sdk $(SDKPATH) [email protected] -import-objc-header $(CBRIDGEHEADER) -o $@ |
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 Int { | |
func asUpperBoundForRandom() -> Int { | |
return Int(arc4random_uniform(UInt32(self))) | |
} | |
func asLengthForRandomAlphanumeric() -> String { | |
let alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".characters | |
var chars: [Character] = [] | |
for _ in 1...self { |
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 | |
let smallSet = Set(Array(1..<999).sort {_, _ in arc4random() % 2 == 0}) | |
let largeSet = Set(Array(1..<99999).sort {_, _ in arc4random() % 2 == 0}) | |
var _count = 999999 | |
let unique: () -> Int = { _count += 1; return _count } | |
var before = NSDate() | |
var after = NSDate() |