Skip to content

Instantly share code, notes, and snippets.

@hikipuro
Last active May 6, 2016 08:51
Show Gist options
  • Save hikipuro/a7ecff43696bd3aafa2d25a0b8d3b636 to your computer and use it in GitHub Desktop.
Save hikipuro/a7ecff43696bd3aafa2d25a0b8d3b636 to your computer and use it in GitHub Desktop.
// http://qiita.com/sushichop/items/ac4ae99b905ce523c2fe
// https ではなく、 http でアクセスする場合は
// info.plist で設定が必要
// http://qiita.com/peromasamune/items/f5b72c4dbd33b5019611
// http://qiita.com/BurialMound/items/87b8c33e2c7ad767c9dc
// [http自体を許可する手順]
// 1. NSAppTransportSecurity を追加
// 2. その下に NSAllowsArbitraryLoads を追加
// 3. YES に設定する
// HTTP-GET
func getAsync() {
print("getAsync")
let urlString = "http://httpbin.org/get"
let request = NSMutableURLRequest(URL: NSURL(string: urlString)!)
// set the method(HTTP-GET)
request.HTTPMethod = "GET"
// use NSURLSessionDataTask
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(
request,
completionHandler: { (data, response, error) in
print("completionHandler")
if error == nil {
let result = NSString(data: data!, encoding: NSUTF8StringEncoding)!
print(result)
} else {
print(error)
}
}
)
task.resume()
}
let alert:NSAlert = NSAlert()
alert.alertStyle = .WarningAlertStyle
alert.messageText = "Message text"
alert.informativeText = "Information text"
let result = alert.runModal()
print("result: ", result)
let panel = NSOpenPanel()
panel.canChooseDirectories = false
panel.canChooseFiles = true
panel.canCreateDirectories = false
panel.allowsMultipleSelection = false
panel.beginSheetModalForWindow(
view.window!,
completionHandler: {(result:Int) -> Void in
print("result: ", result)
}
)
/*
let result = panel.runModal()
switch result {
case NSModalResponseOK:
print("NSOKButton: ", panel.URL!.path!)
case NSModalResponseCancel:
print("NSCancelButton")
default:
print("default")
}
*/
// http://tiny-wing.hatenablog.com/entry/2015/11/04/092413
class ViewController: NSViewController {
var count = 0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
NSTimer.scheduledTimerWithTimeInterval(
1.0,
target: self,
selector: #selector(update(_:)),
userInfo: count,
repeats: true
)
}
func update(timer: NSTimer) {
count += 1
if count > 2 {
timer.invalidate()
}
print("update(): ", count)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment