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 Cocoa | |
let session = NSURLSession.sharedSession() | |
let request = NSURLRequest(URL: NSURL(string: "http://example.com")!) | |
let dataToUpload = "Some Arbitrary Data".dataUsingEncoding(NSUTF8StringEncoding) | |
let uploadTask = session.uploadTaskWithRequest(request, fromData: dataToUpload, | |
completionHandler: { (responseData, response, error) in | |
// Check on some response headers (if it's HTTP) |
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 GridPiece {} | |
// This compiles | |
class ReadOnlyGrid { | |
subscript(position: (x: Int, y: Int)) -> GridPiece { | |
return GridPiece() | |
} | |
} | |
// And this compiles |
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
// A simple data source containing basic string 'notes' | |
class Notes { | |
private var notesArray = [String]() | |
// Get & Set with some safety logic | |
subscript(index: Int) -> String { | |
// `note` arg is implicitly String (subscript return type) | |
set (note) { | |
if index < 0 { | |
notesArray.insert(note, atIndex: 0) |
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
// Get the file manager | |
let fileManager = NSFileManager.defaultManager() | |
// Get the app's available documents directories | |
// For other options usable in iOS besides .DocumentsDirectory see: | |
// http://stackoverflow.com/questions/7268299/path-directory-usable-in-ios | |
let directoryURLs = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask) as [NSURL] | |
// Cast to [NSURL] because it 'helpfully' gives back [AnyObject] | |
// iOS should only give you a single documents directory for your app |