What does the /private prefix on an iOS file path indicate?

前端 未结 6 903
孤城傲影
孤城傲影 2020-12-14 15:34

I have a bug when my app runs on the iPhone but not when it runs on the simulator. I was using the length of the home directory path to extract the relative path of a file

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 15:55

    A function (Swift 5) to remove an file from cache. I had a lot of problems and the use of the URL solved the /private issue.

    class func removeFileFromCache( filePattern: String ) -> Bool {
        // find filename with pattern
         
        do {
            let cachePath = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
            let filePathUrl = URL( fileURLWithPath: filePattern )
            let originalFilename = filePathUrl.lastPathComponent
            let newFilePath = cachePath.appendingPathComponent( originalFilename ).path
           
            try FileManager.default.removeItem(atPath: newFilePath )
            print("file \( filePattern ) succesfull removed.",classname:URL(fileURLWithPath: #file).lastPathComponent )
            
        } catch let error as NSError {
            print("Error \(error)",classname:URL(fileURLWithPath: #file).lastPathComponent )
            return false // all is not well
        }
        
        return true
    }
    

提交回复
热议问题