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 | |
class GenericTVCDelegate<A> : NSObject, UITableViewDataSource { | |
var cellCreator:A->UITableViewCell | |
var data:[A] | |
init(cellCreator:A->UITableViewCell, data:[A]) { | |
self.cellCreator = cellCreator | |
self.data = data | |
} | |
//} |
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
final class Bar { | |
var i = 0 | |
} | |
struct Foo { | |
var i:Int { | |
get { | |
return bar.i | |
} | |
set { |
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 protocol StringyType { | |
var string:String { get } | |
init(_ string:String) | |
} | |
extension String : StringyType { | |
public var string:String{ return self } | |
public init(_ string:String) { | |
self = string | |
} |
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 testAssert(x:Int)->Int { | |
var res = 0 | |
if x > 0 { | |
res += 3 | |
assertionFailure("testAssert") | |
res += 5 | |
return res |
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 | |
/// http://swapi.co/api/starships/?format=json With "'s escaped. | |
let starshipsJSON = "{\"count\":36,\"next\":\"http://swapi.co/api/starships/?format=json&page=2\",\"previous\":null,\"results\":[{\"name\":\"Sentinel-class landing craft\",\"model\":\"Sentinel-class landing craft\",\"manufacturer\":\"Sienar Fleet Systems, Cyngus Spaceworks\",\"cost_in_credits\":\"240000\",\"length\":\"38\",\"max_atmosphering_speed\":\"1000\",\"crew\":\"5\",\"passengers\":\"75\",\"cargo_capacity\":\"180000\",\"consumables\":\"1 month\",\"hyperdrive_rating\":\"1.0\",\"MGLT\":\"70\",\"starship_class\":\"landing craft\",\"pilots\":[],\"films\":[\"http://swapi.co/api/films/1/\"],\"created\":\"2014-12-10T15:48:00.586000Z\",\"edited\":\"2014-12-22T17:35:44.431407Z\",\"url\":\"http://swapi.co/api/starships/5/\"},{\"name\":\"Death Star\",\"model\":\"DS-1 Orbital Battle Station\",\"manufacturer\":\"Imperial Department of Military Research, Sienar Fleet Systems\",\"cost_in_credits\":\"1000000000000\",\"length\":\"120000\ |
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 | |
/// http://swapi.co/api/starships/?format=json With "'s escaped. | |
let starshipsJSON = "{\"count\":36,\"next\":\"http://swapi.co/api/starships/?format=json&page=2\",\"previous\":null,\"results\":[{\"name\":\"Sentinel-class landing craft\",\"model\":\"Sentinel-class landing craft\",\"manufacturer\":\"Sienar Fleet Systems, Cyngus Spaceworks\",\"cost_in_credits\":\"240000\",\"length\":\"38\",\"max_atmosphering_speed\":\"1000\",\"crew\":\"5\",\"passengers\":\"75\",\"cargo_capacity\":\"180000\",\"consumables\":\"1 month\",\"hyperdrive_rating\":\"1.0\",\"MGLT\":\"70\",\"starship_class\":\"landing craft\",\"pilots\":[],\"films\":[\"http://swapi.co/api/films/1/\"],\"created\":\"2014-12-10T15:48:00.586000Z\",\"edited\":\"2014-12-22T17:35:44.431407Z\",\"url\":\"http://swapi.co/api/starships/5/\"},{\"name\":\"Death Star\",\"model\":\"DS-1 Orbital Battle Station\",\"manufacturer\":\"Imperial Department of Military Research, Sienar Fleet Systems\",\"cost_in_credits\":\"1000000000000\",\"length\":\"120000\ |
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
enum JSONParseResult { | |
case Success(AnyObject) | |
case Error(NSError) | |
} | |
/// Parses UTF-8 data to the appropriate object. | |
func parseJSON(data:NSData)->(JSONParseResult) { | |
var err:NSError? | |
let parsed:AnyObject? = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments, error: &err) | |
if let err = err { |
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 | |
var str = "Hello, playground" | |
let jsonStr = "{\"user\": {\"name\": \"jquave\",\"id\": 542,\"url\": \"http://jamesonquave.com\"},\"friend_ids\": [299,341,492],\"alert_message\": \"Please verify e-mail address to continue\"}" | |
var err:NSError? | |
let data = jsonStr.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) ?? NSData() | |
typealias JSONDict = [String: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
// Will be fixed | |
let sub:SubClass = s as? SubClass ?? SubClass(2) | |
// Use this for Beta 1 | |
let sub:SubClass = (s as? SubClass) ?? SubClass(2) | |
// Setup | |
let dict:[String:Int]? = ["a":1, "b":2] | |
// Swift 1.1 - Removed | |
let x:Int? = dict.map { $0["a"] }? | |
// Swift 1.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
class Swift_1_2 { | |
static var v = UIView() | |
static let d = [ "a" : 1, "b" : 3 ] | |
static func bar() { | |
let x: Set<Int> | |
if let a = d["a"], b = d["b"] where a < b { | |
x = [a, b, b-a] | |
} else { | |
x = [] | |
} |