Swift:在String内增加Int的问题

时间:2017-07-13 20:24:41

标签: ios swift string int

我想在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()

1 个答案:

答案 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