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
| newStr = "hello 😂😒😡" | |
| // the number of elements: | |
| let count = newStr.utf16Count | |
| // create array of appropriate length: | |
| var array = [UInt16](count: count, repeatedValue: 0) | |
| for a in enumerate(newStr.utf16) { |
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
| // LINKED LIST | |
| /** | |
| * NODE | |
| */ | |
| private class Node<T:protocol<Printable, Comparable>>: Printable, Comparable { | |
| /** | |
| * PROPERTIES | |
| */ | |
| var info:T |
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 TakeSequenceView<Base : SequenceType> : SequenceType { | |
| let base: Base | |
| let n: Int | |
| init(_ base: Base, n: Int) { | |
| self.base = base | |
| self.n = n | |
| } | |
| func generate() -> GeneratorOf<Base.Generator.Element> { |
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 | |
| extension String | |
| { | |
| // Works in Xcode but not Playgrounds because of a bug with .insert() | |
| mutating func insertString(string:String,ind:Int) { | |
| var insertIndex = advance(self.startIndex, ind, self.endIndex) | |
| for c in string { |
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
| // Playground - noun: a place where people can play | |
| import Cocoa | |
| enum Wildcard : NilLiteralConvertible { | |
| case Single | |
| case FromBeginning | |
| case ToEnd | |
| case Range(Int) | |
| case Literal(Int) |
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 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 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 | |
| protocol SomeDelegateProtocol : class { | |
| func firstFunc() -> String | |
| func secondFunc() -> Bool | |
| func thirdFunc() -> Self | |
| } | |
| class MyClass { | |
| weak var delegate : SomeDelegateProtocol? |
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
| // | |
| // Queue.swift | |
| // NTBSwift | |
| // | |
| // Created by Kåre Morstøl on 11/07/14. | |
| // | |
| // Using the "Two-Lock Concurrent Queue Algorithm" from http://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html#tlq, without the locks. | |
| // should be an inner class of Queue, but inner classes and generics crash the compiler, SourceKit (repeatedly) and occasionally XCode. |
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 Darwin | |
| import CoreGraphics | |
| protocol ScalarFunctions { | |
| var acos:Double {get} | |
| var asin:Double {get} | |
| var atan:Double {get} | |
| func atan2(x:Double) -> Double | |
| var cos:Double {get} | |
| var sin:Double {get} |
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 Array { | |
| func contains(object:AnyObject) -> Bool { | |
| return self.bridgeToObjectiveC().containsObject(object) | |
| } | |
| func indexOf(object:AnyObject) -> Int { | |
| return self.bridgeToObjectiveC().indexOfObject(object) | |
| } | |
| } |