swfit闭包截取闭包外部值

2017-12-01  本文已影响5人  朽木自雕也

'''
let fileURL: URL;
let destination: DownloadRequest.DownloadFileDestination = { _, _ in
return (fileURL, [.createIntermediateDirectories, .removePreviousFile])
}
'''
上面代码会报错,错误的原因是fileURL只是声明但是并没有初始化,初始化后就不回报错了,改成代码如下,错误就没有了,path只是我这里举个例子
'''
//获取沙盒路径
let path = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask,
true).last! as String
let fileURL: URL = URL(fileURLWithPath: path)
let destination: DownloadRequest.DownloadFileDestination = { _, _ in
return (fileURL, [.createIntermediateDirectories, .removePreviousFile])
}
'''

上一篇下一篇

猜你喜欢

热点阅读