1
の中でInt
の値をインクリメントしようとしていますが、インクリメントが1回しか発生しないのはなぜですか?ここでのコードは次のとおりです。Swift:文字列内のインクリメントIntの問題
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
}
}
}
:
let downloadFile = DownloadFile(url: url)
downloadFile.startDownload()
あなたは1に番号を設定し、その後、それを2に増やしてください。あなたはこれからどのような行動を期待していましたか? – Connor
@ConnorGクラスを開始するたびに、数字がFile1、File2、File3 –