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 UIKit | |
import XCPlayground | |
import Social | |
// Fetch image and convert JPEG data to base64 representation | |
let image = UIImage(named:"Quote")! | |
let base64String = UIImageJPEGRepresentation(image, 1.0).base64EncodedStringWithOptions(.Encoding64CharacterLineLength) | |
// Establish post dictionary | |
var post = [NSObject:AnyObject]() |
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
// Take 4 (aka the akempgen approach): | |
var fibGenerator = GeneratorOf{_ -> Int? in fibs.append(fibs.reduce(0, combine:+)); return fibs.removeAtIndex(0)} | |
// Take 3 | |
var fibGenerator = GeneratorOf{_ -> Int? in | |
fibs.append(fibs.reduce(0, combine:+)) | |
return fibs.removeAtIndex(0) | |
} | |
// Take 2 |
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
func Scramble<C: MutableCollectionType where C.Index == Int>(var collection: C) -> C { | |
let elementCount = count(collection) | |
for index in dropLast(Array(0..<elementCount)) { | |
let r = index + Int(arc4random_uniform(numericCast(elementCount - index))) | |
swap(&collection[index], &collection[r]) | |
} | |
return collection | |
} |
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 struct StderrOutputStream: OutputStreamType { | |
// Support for file redirection back to console | |
private static var fpos : fpos_t = 0 | |
private static var fd = dup(fileno(stderr)) | |
private static var isRedirected_ = false | |
public static var isRedirected : Bool {return isRedirected_} | |
// When false, the output file is rewritten and not appended | |
private static var appendToFile = true |
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 String { | |
var utf8Representation : String { | |
var utf8String = "" | |
for c in self.unicodeScalars { | |
let inputArray : [UInt32] = [c.value] | |
var outputArray = [UInt8]() | |
var output = SinkOf<UInt8>{outputArray.append($0)} | |
let error = transcode(UTF32.self, UTF8.self, inputArray.generate(), &output, stopOnError: true) | |
if !error { | |
let s = String(bytes:outputArray, encoding:NSUTF8StringEncoding)! |
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
// Enums. They're not just for breakfast anymore. | |
// This is a simple enumeration that's based on numeric values, | |
// just like you'd use in many other programming languages | |
enum Dwarf : Int { | |
case Bashful = 1, Doc, Dopey, Grumpy, Happy, Sleepy, Sneezy | |
} | |
// And instantiate them. Hi Sleepy. | |
var d : Dwarf = .Sleepy // shows (Enum Value) in gutter | |
println(d) // initially prints (Enum Value) in console until you add the following extension (so much for playground's top to bottom evaluation guarantee) |
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
Monday 2:30 PM Platforms State of the Union | |
Dev Tools | |
Tues 1:30 PM | |
Tues 2:30 PM | |
Tues 3:30 PM Improving your Existing Apps with Swift | |
Weds 9:00 AM | |
Weds 10:00 AM |
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 UIKit | |
struct BitFlagSet: RawOptionSetType, BooleanType, Printable, DebugPrintable { | |
// Settable bit count applies to all instances of the struct | |
private static var bitCount_ : UInt = 8 | |
static var bitCount : UInt {get{return bitCount_} set{bitCount_ = min(max(newValue, 1), 64)}} | |
static var allOnes : BitFlagSet {return BitFlagSet(rawValue:(bitCount_ < 64 ? UInt(1 << bitCount_) - 1 : UInt.max))} | |
static var allZeros: BitFlagSet {return BitFlagSet(rawValue: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
for appID in appIDs { | |
let urlString = "https://itunes.apple.com/lookup?id=" + appID | |
if let | |
url = NSURL(string:urlString), | |
data = NSData(contentsOfURL: url), | |
json = NSJSONSerialization.JSONObjectWithData( | |
data, options: NSJSONReadingOptions(0), | |
error: nil) as? NSDictionary, | |
resultsList = json["results"] as? NSArray, | |
results = resultsList.firstObject as? NSDictionary, |
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 | |
import Cocoa | |
import XCPlayground | |
public let DropNotification = "DropNotification" | |
public class DropWindow : NSWindow { | |
required public init?(coder: NSCoder) { | |
super.init(coder: coder) | |
self.registerForDraggedTypes([NSFilenamesPboardType]) |