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
func testFunc() { | |
for i in 0...100 { | |
let y = i * 10 | |
} | |
} | |
testFunc() |
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 DataEncodable<T> { | |
static func encode(var value: T) -> NSData { | |
return withUnsafePointer(&value) { NSData(bytes: $0, length: sizeof(T)) } | |
} | |
static func decode(data: NSData) -> T { | |
let pointer = UnsafeMutablePointer<T>.alloc(sizeof(T)) | |
data.getBytes(pointer, length: sizeof(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
func encode(var value: T) -> NSData { | |
return withUnsafePointer(&value) { NSData(bytes: $0, length: sizeof(T)) } | |
} | |
func decode(data: NSData) -> T { | |
let pointer = UnsafeMutablePointer<T>.alloc(sizeof(T)) | |
data.getBytes(pointer, length: sizeof(T)) | |
return pointer.move() | |
} |
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
#!/bin/sh | |
#ID='A16FF353-8441-459E-A50C-B071F53F51B7' # Xcode 6.2 | |
#ID='992275C1-432A-4CF7-B659-D84ED6D42D3F' # Xcode 6.3 | |
ID='9F75337B-21B4-4ADC-B558-F9CADF7073A7' # Xcode 6.3 GM | |
PLIST_BUDDY=/usr/libexec/PlistBuddy | |
function add_compatibility() { | |
"$PLIST_BUDDY" -c "Add DVTPlugInCompatibilityUUIDs:10 string $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
let startTime = CACurrentMediaTime() | |
var sum = 0 | |
for var i = 0; i < 100_000_000; i++ { | |
//sum += Int(arc4random_uniform(UINT32_MAX)) | |
sum += i | |
} | |
let totalTime = CACurrentMediaTime() - startTime | |
print("time: - \(totalTime) sec") | |
print("total: \(sum)") |
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
double startTime = clock(); | |
unsigned int sum = 0; | |
for (int i = 0; i < 100000000; i++) { | |
// sum += arc4random_uniform(UINT32_MAX); | |
sum += i; | |
} | |
double endTime = clock(); | |
double totalTime = (endTime — startTime) / CLOCKS_PER_SEC; |
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
//Default value | |
func sum4(x: Int, y: Int, maybe: Int = 1) -> Int { | |
return x + y + maybe | |
} | |
let params4 = (1, 5, 1) | |
let params4_1 = (1, 5, maybe: 1) | |
sum4(1, 5, maybe: 1) | |
sum4(1, 5) |
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
func sum(x: Int, y: Double) {} // no names (,) | |
let params = (1, 1.0) //no names | |
sum(params) // works fine | |
func other(# x: Int, # y: Double) // name (x, y) | |
other(params) //Fails | |
let paramsOther = (x: 1, y: 1.0) //name (x, y) | |
other(paramsOther) //Works! |
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
func sum(x: Int, y: Double) {} // type (Int, Double) | |
let params = (1, 1.0) //type (Int, Double) | |
let paramsWrongOrder = (1.0, 1) //type (Double, Int) | |
let oneParam = (1) //type (Int) | |
sum(params) // works fine | |
sum(oneParam) //Fails | |
sum(paramsWrongOrder) //Fails | |
func other(x: Int, y: String) {} // type (Int, 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 | |
// Rename file to TupleAndFunction.playground | |
import Cocoa | |
func sum(x: Int, y: Int) -> Int { | |
return x + y | |
} | |
func sum1(# x: Int, y: Int) -> Int { | |
return x + y |