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
struct PrimeGenerator : Generator { | |
typealias Element = Int | |
private var myPrimes = [Int]() // store previous primes | |
var current : Int = 2 // first prime is 2 | |
mutating func next() -> Int? { | |
if myPrimes.count == 0 {myPrimes = [2]; return 2} | |
NextNumber: while (current++ > 0) { | |
for prime in myPrimes { | |
// If a number has a prime factor it is not prime |
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 should have worked. It doesn't work. | |
// Out of range error because the String.Index is set with regard to the smallest string at match | |
//extension String { | |
// | |
// func findIndexOf(substring : String) -> String.Index? { | |
// if countElements(self) < countElements(substring) {return nil} | |
// if countElements(substring) == 0 {return nil} | |
// if self.hasPrefix(substring) {return self.startIndex} | |
// if let recursionResults = dropFirst(self).findIndexOf(substring) { |
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 Array { | |
func takeWhile(processingClosure : Element->Bool) -> [Element] { | |
if (self.count == 0) {return []} | |
let car : Element = self.first! | |
if processingClosure(car) { | |
let cdr : [Element] = Array(self[self.startIndex.successor()..<self.endIndex]) | |
return [car] + cdr.takeWhile(processingClosure) | |
} else { | |
return [] | |
} |
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
Testing iPhone 6 plus | |
iPhone Simulator | |
iPhone OS | |
8.0 | |
iPhone Simulator | |
<UIView: 0x7f854596f7a0; frame = (0 0; 414 736); autoresize = W+H; layer = <CALayer: 0x7f854596bd50>> | |
<UIWindow: 0x7f854596e1e0; frame = (0 0; 414 736); gestureRecognizers = <NSArray: 0x7f854596edd0>; layer = <UIWindowLayer: 0x7f854596c0d0>> | |
Testing iPhone 6 | |
iPhone Simulator |
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 | |
func QLString(x : QuickLookObject) -> String { | |
switch x { | |
case .Text(let s) : return "[Text] " + s | |
case .Int(let i) : return "[Int] " + "\(i)" | |
case .UInt(let u) : return "[UInt] " + "\(u)" | |
case .Float(let f) : return "[Float] " + "\(f)" | |
case .Image(let img) : return "[Image] " + "[image]" | |
case .Sound(let snd) : return "[Sound] " + "[sound]" |
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
postfix operator ⟹ {} | |
postfix func ⟹ <T:_ObjectiveCBridgeable>(obj : T) -> AnyObject { return _bridgeToObjectiveC(obj)! } | |
var s = "23.692" | |
NSString(string:s).doubleValue | |
s⟹.doubleValue |
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
// MARK: Mirror-based Utilities | |
// These work across arrays, structures, tuples | |
// Goatees are mandatory | |
func mirrorDo<S>(structure:S, closure:(Int, String, Any)->()) { | |
let mirror = reflect(structure) | |
for index in 0 ..< mirror.count { | |
closure(index, mirror[index].0, mirror[index].1.value) | |
} | |
} |
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
public extension UIBezierPath { | |
public var dashPhase : CGFloat? { | |
get { | |
// Only defined if dashes are defined | |
if dashes.count == 0 {return nil} | |
var phase = UnsafeMutablePointer<CGFloat>.alloc(1) | |
getLineDash(nil, count: nil, phase: phase) | |
let result = phase.memory; free(phase) | |
return result | |
} |
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
var interpolatedPathPoints : [CGPoint] { | |
let numberOfBezierSamples = 6 | |
var results = [CGPoint]() | |
var current : BezierElement? = nil | |
for element in elements { | |
switch element.elementType.value { | |
case kCGPathElementMoveToPoint.value: | |
if let point = element.point {results += [point]; current = element} | |
break; | |
case kCGPathElementAddLineToPoint.value: |
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
// | |
// LaunchAtLoginHelper.swift | |
// | |
// Created by Erica Sadun on 4/1/15. | |
// Copyright (c) 2015 Erica Sadun. All rights reserved. | |
// | |
import Foundation | |
public func getLoginItems() -> LSSharedFileList? { |