[categories] [index] [all (531)] [latest]
if ("ABCDE" as NSString).containsString("BC") {
println("Containing")
}
let group = dispatch_group_create()
let mainQueue = dispatch_get_main_queue()
for i in 1...10 {
dispatch_group_enter(hgReadGroup)
longSubTask(param:String, completionHandler: { (results) -> () in
// ...
dispatch_group_leave(group)
})
}
dispatch_group_notify(group, mainQueue) {
print("-> all subtasks are finished")
completionHandler(entries:entries)
}
let date = NSDate()
let name: AnyClass! = object_getClass(date) // __NSDate
let string = "Hello"
let name = string.dynamicType // Swift.String
also:
class MyClass { }
let o : AnyObject = MyClass()
print(o is String) // false
print(o is MyClass) // true
guard let data = optionalData,
optionalDict = try? NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers) as? [String:AnyObject],
d = optionalDict,
latestVersionString = d["latest_version_string"] as? String,
latestVersionURL = d["latest_version_url"] as? String else {
return
}
static var x = {
// ...
return xxx
}()
let date = NSDate()
let unitFlags: NSCalendarUnit = [.Hour, .Day, .Month, .Year]
let components = NSCalendar.currentCalendar().components(unitFlags, fromDate: date)
$ xcrun swift
Welcome to Swift! Type :help for assistance.
1> var x = "toto"
x: String = "toto"
2> println(x)
toto
3>
private var stravaAPI : StravaAPI = {
return StravaAPI()
}()
public class Person {
public private(set) var name: String
// ...
}
#!/usr/bin/swift
/*
$ swift x.swift
*/
import Foundation
for arg in Process.arguments {
print(arg)
}
static let dateFormatter: NSDateFormatter = {
let df = NSDateFormatter()
df.dateFormat = "yyyyMMdd"
return df
}()
struct Board {
var cells : [[Int]]
init(row:Int, columns:Int) {
self.cells = [[Int]]()
for _ in 0..<row {
self.cells.append([Int](count: columns, repeatedValue: 0))
}
}
subscript(row: Int, column: Int) -> Int {
get {
return cells[row][column]
}
set {
cells[row][column] = newValue
}
}
}
var b = Board(row: 3, columns: 4)
b[1,1] = 1
print(b[1,1])
#!/usr/bin/env xcrun --toolchain com.apple.dt.toolchain.XcodeDefault swift
// -F/my/frameworks add to search path
// -framework MyUtils.framework load framework
// -D FLAG compilation flag
import Foundation
print(CommandLine.arguments)
class MyClass {
static let sharedInstance = MyClass()
}