Skip to content

Instantly share code, notes, and snippets.

@asus4
Created July 10, 2014 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asus4/a400ed14310c3cf9d05f to your computer and use it in GitHub Desktop.
Save asus4/a400ed14310c3cf9d05f to your computer and use it in GitHub Desktop.
let date = NSDate()
let dateFormatter = NSDateFormatter()
dateFormatter.setDateFormat("yyyy-MM-dd-HH-mm-ss")
let dateStr = dateFormatter.stringFromDate(date)
typedef void (^JsonDelegate)(NSDictionary json);
class TheDelegteSample {
// 定義
typealias JsonDelegate = (json:NSDictionary) -> ()
// 変数
var jsonDelegate:JsonDelegate?
// 叩く
func foo() {
if jsonDelegate {
jsonDelegate(json:theJson)
}
}
}
// デスクトップから取得。構造体になってるので注意
let directory = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DesktopDirectory, NSSearchPathDomainMask.UserDomainMask, true)
let directoryStr = directory[0] as NSString
let path = NSString(format: "%@/%@.txt", directoryStr, "thefile")
let url = NSURL(fileURLWithPath:path)
// dispatch_get_main_queueは廃止
// 5秒後に
let offset = 5.0
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(offset * Double(NSEC_PER_SEC))),dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),{
// TODO dispatch
})
// Background Task
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, {
// Background
})
import Cocoa
class SoundManager {
struct Cache {
static let sound = Dictionary<String, NSSound>()
}
init() {
}
class func getSound(name:String) -> NSSound {
var sound = Cache.sound[name]
if sound == nil {
let soundpath = NSBundle.mainBundle().pathForResource(name, ofType:"aif")
sound = NSSound(contentsOfFile: soundpath, byReference: false)
}
return sound!
}
class func play(name:String) {
let sound = SoundManager.getSound(name)
sound.play()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment