NSFileManager unique file names

前端 未结 9 1957
生来不讨喜
生来不讨喜 2020-12-23 10:54

I need a quick and easy way to store files with unique file names on iOS. I need to prefix the file with a string, and then append the generated unique identifier to the en

9条回答
  •  暖寄归人
    2020-12-23 11:31

    Here is what I ended up using in Swift 3.0

    public func generateUniqueFilename (myFileName: String) -> String {
    
        let guid = ProcessInfo.processInfo.globallyUniqueString
        let uniqueFileName = ("\(myFileName)_\(guid)")
    
        print("uniqueFileName: \(uniqueFileName)")
    
        return uniqueFileName
    }
    

提交回复
热议问题