Instantly share code, notes, and snippets.

View arrayExtension.swift
extension Array where Element: Int {
func foo() {
}
}
var anArray = [Int]()
anArray.foo() // '[Int]' does not have a member named 'foo'
View Fibonacci.swift
// Fibonacci series
// F[n] = F[n-1] + F[n-2]
// 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144
// Find the fibonacci number for n interations
func fibonacci(n: Int) {
var num1 = 0
var num2 = 1
View autoBuildNumber
# @desc Auto-populate the build number based on the current date and time.
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Drag the "Run Script" below "Target Dependencies"
now=`date +%y.%m.%d.%H%M`
buildNumber=$(printf "%s" $now)
View Clamp.swift
///Returns the input value clamped to the lower and upper limits.
func clamp<T: Comparable>(value: T, lower: T, upper: T) -> T {
return min(max(value, lower), upper)
}
//-----------------------------------------------
// Example usage
let proposedIndex = 6
View Xcode Project Line Count
# Count the lines of code in a Xcode project
find . "(" -name "*.m" -or -name "*.mm" -or -name "*.cpp" ")" -print0 | xargs -0 wc -l