我想在Int
内增加String
值,但我不知道增量只发生一次的原因!这是代码:
class DownloadFile : NSObject {
var number = 1
init(url : String) {
urlOfDownload = url
fileUrl = URL(string: url)!
//Added by me , checks if file is already exist try to add new file name
let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first! as String
let url = NSURL(fileURLWithPath: path)
let filePath = url.appendingPathComponent(fileUrl.lastPathComponent)!.path
let fileManager = FileManager.default
if fileManager.fileExists(atPath: filePath) {
number += 1
print("FILE AVAILABLE")
nameOfDownload = "\(fileUrl.deletingPathExtension().lastPathComponent)\(number).\(fileUrl.pathExtension)"
} else {
print("FILE NOT AVAILABLE")
nameOfDownload = fileUrl.lastPathComponent
}
}
}
使用class:
let downloadFile = DownloadFile(url: url)
downloadFile.startDownload()
答案 0 :(得分:4)
您需要让$ python -V
Python 2.7.13
$ pip --version
pip 8.1.2 from E:\PythonAnaconda\lib\site-packages (python 2.7)
$ conda --version
conda 4.3.22
var
在类实例之间共享:
static