Update files documentation
This commit is contained in:
parent
8bc1f18e12
commit
46de9ae0d4
|
@ -11,12 +11,18 @@ public class BundleFileFinder: FileFinder {
|
|||
|
||||
private let bundle: Bundle
|
||||
|
||||
/**
|
||||
Find files with names that start with a certain prefix.
|
||||
*/
|
||||
public func findFilesWithFileNamePrefix(_ prefix: String) -> [String] {
|
||||
let format = "self BEGINSWITH %@"
|
||||
let predicate = NSPredicate(format: format, argumentArray: [prefix])
|
||||
return findFilesWithPredicate(predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
Find files with names that end with a certain suffix.
|
||||
*/
|
||||
public func findFilesWithFileNameSuffix(_ suffix: String) -> [String] {
|
||||
let format = "self ENDSWITH %@"
|
||||
let predicate = NSPredicate(format: format, argumentArray: [suffix])
|
||||
|
|
|
@ -6,6 +6,13 @@ import Foundation
|
|||
*/
|
||||
public protocol FileFinder {
|
||||
|
||||
/**
|
||||
Find files with names that start with a certain prefix.
|
||||
*/
|
||||
func findFilesWithFileNamePrefix(_ prefix: String) -> [String]
|
||||
|
||||
/**
|
||||
Find files with names that end with a certain suffix.
|
||||
*/
|
||||
func findFilesWithFileNameSuffix(_ suffix: String) -> [String]
|
||||
}
|
||||
|
|
|
@ -28,11 +28,25 @@ public class StandardFileExporter: FileExporter {
|
|||
case invalidUrl
|
||||
}
|
||||
|
||||
/**
|
||||
Delete a previously exported file.
|
||||
|
||||
This function should be called when you are done with a
|
||||
file, to avoid that the file system fills up with files
|
||||
that are no longer used.
|
||||
*/
|
||||
public func deleteFile(named fileName: String) {
|
||||
guard let url = getFileUrl(forFileName: fileName) else { return }
|
||||
try? fileManager.removeItem(at: url)
|
||||
}
|
||||
|
||||
/**
|
||||
Export the provided data to a certain file.
|
||||
|
||||
The resulting file url will depend on the file exporter
|
||||
implementation. For instance, the `StandardFileExporter`
|
||||
will store the file in the specified directory.
|
||||
*/
|
||||
public func export(data: Data, to fileName: String, completion: @escaping Completion) {
|
||||
guard let url = getFileUrl(forFileName: fileName) else { return completion(.failure(ExportError.invalidUrl)) }
|
||||
tryWrite(data: data, to: url, completion: completion)
|
||||
|
|
Loading…
Reference in New Issue