unable to delete file from the app documents folder
Do not use colons in file names.
(For legacy reasons) the OS treats them as path separators and replaces them with slashes.
How to reproduce UIDocumentUIPickerViewController NSCocoaErrorDomain Code=260?
As Thomas Deniau suggested in the comments, we managed to reproduce the bug by saving it to files. Check this answer.
FileManager returns url with Nil instead of file on it
Found apple documentation about getting access to directories. Edited my code to this and now it is working
guard urls.first!.startAccessingSecurityScopedResource() else {
print("Error getting access")
return
}
defer { urls.first!.stopAccessingSecurityScopedResource() }
let path = urls.first!.path
let stream = InputStream(url: URL(fileURLWithPath: path))
do {
let csv = try CSVReader(stream: stream!)
print("Everything is ok")
while let row = csv.next() {
print(row)
}
URL(fileURLWithPath: path).stopAccessingSecurityScopedResource()
} catch {
print(error)
}
Basically before working with the URL you get the request to use secured URL by this function
guard urls.first!.startAccessingSecurityScopedResource() else {
print("Error getting access")
return
}
defer { urls.first!.stopAccessingSecurityScopedResource() }
And end working with secured connection by writing this line
URL(fileURLWithPath: path).stopAccessingSecurityScopedResource()
However code written in documentation is not working for me, and error check(that i deleted) still giving me an error
Update
If code is not working, you can delete this line
defer { urls.first!.stopAccessingSecurityScopedResource() }
Related Topics
Nsattributedstring Boundingrect Returns Wrong Height
Swiftui - Form with Error Message on Button Press and Navigation
Turn Off Touch for Whole Screen, Spritekit, How
Allocating Ekeventstore Throws Warnings
Mac App Disappears When Window Is Closed Then Another App Is Selected
How to Put a View with Loadmore Button in UItableview After The Cell
What Is The Intended Use of Optional Variable/Constant in Swift
Binary Search: Error in Passing Array
How to Fix Dylib with Invalid Signature
How Does Swift's Int Literal to Float Inference Work
How to Get The Range of The First Line in a String
Convert Data to Dispatchdata in Swift 4
How to Resolve Rctpromiseresolveblock After Bftask
Decrypting Des with Commoncrypto in Swift 3
Convert Gregorian Date to Hijri Date
Transparency Issues with Repeated Stamping of Textures on an Mtkview