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
// Playground - noun: a place where people can play | |
import Foundation | |
func numberOfBits(bytes:[Byte]) -> Int { | |
if (bytes.count == 0) { | |
return 0; | |
} | |
var toRemove = 0; |
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
// Marcin Krzyżanwski | |
// Code for https://github.com/krzyzanowskim/CryptoSwift/issues/20 | |
// PHP | |
function encrypt($plaintext, $key, $iv) { | |
$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext, MCRYPT_MODE_CBC, $iv); | |
return base64_encode($ciphertext); | |
} | |
function decrypt($ciphertext_base64, $key, $iv) { |
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
class Foo { | |
var some:String = "string" | |
func One() { | |
func Nested(weakSelf:Foo) { | |
if (weakSelf.some == "integer") { // no error | |
} | |
} | |
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
// Version 6.3 (6D532l) | |
protocol Proto { | |
init() | |
} | |
struct S1: Proto { | |
init() {} | |
} |
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
// Playground - noun: a place where people can play | |
import Foundation | |
typealias Byte = UInt8 | |
protocol GenericIntegerType: IntegerType { | |
init(_ v: Int) | |
init(_ v: UInt) | |
init(_ v: Int8) |
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 | |
let arr1 = [] | |
arr1 is NSArray // true | |
arr1 is NSMutableArray // false | |
arr1.append(1) // 'NSArray' does not have a member named 'append' | |
var arr2 = [] | |
arr2 is NSArray // true | |
arr2 is NSMutableArray // false |
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 { | |
/** split in chunks with given chunk size */ | |
func chunks(chunksize:Int) -> [Array<T>] { | |
var words:[[T]] = [[T]]() | |
words.reserveCapacity(self.count / chunksize) | |
for var idx = chunksize; idx <= self.count; idx = idx + chunksize { | |
let word = Array(self[idx - chunksize..<idx]) // this is slow | |
words.append(word) // slower than this |
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 perf(text: String, closure: () -> ()) { | |
let measurementStart = NSDate(); | |
closure() | |
let measurementStop = NSDate(); | |
let executionTime = measurementStop.timeIntervalSinceDate(measurementStart) | |
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
let array = [[[[UInt8]]]](count: 1, repeatedValue: | |
[[[UInt8]]](count: 2, repeatedValue: | |
[[UInt8]](count: 2, repeatedValue: | |
[UInt8](count: 2, repeatedValue: 0)))) |
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 | |
public class Foo { | |
private var key:NSData | |
private var goo:NSData? | |
public init(key: NSData) { | |
self.key = key | |
self.goo = nil | |
} |