forked from icepy/Front-End-Develop-Guide
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathContents.swift
21 lines (16 loc) · 880 Bytes
/
Contents.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//: Playground - noun: a place where people can play
import UIKit
import Foundation
let downloadURL:String = "https://github.com/nemoTyrant/manong"
var request:NSURLRequest = NSURLRequest(URL: NSURL(string: downloadURL)!)
var fileManager:NSFileManager = NSFileManager.defaultManager()
let homePath:String = NSHomeDirectory()
let filePath:String = homePath.stringByAppendingPathComponent("/github/Front-End-Develop-Guide/manong.html")
let config:NSURLSessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration()
let session:NSURLSession = NSURLSession(configuration: config)
let task: NSURLSessionDataTask = session.dataTaskWithRequest(request, completionHandler: { (data:NSData!, response:NSURLResponse!, error:NSError!) -> Void in
if (error == nil){
fileManager.createFileAtPath(filePath, contents: data, attributes: nil)
}
})
task.resume()