Files 4.0
Files 4.0 brings a brand new, streamlined implementation, improved error handling, more thorough documentation, and a more modern API. Since it's a new major release, some breaking API changes have been made. Here's everything that's new:
- The
FileSystem
class has been removed. To perform operations relative to the root of the file system, use the newFolder.root
API instead. To use a customFileManager
, callmanagedBy()
on anyFile
orFolder
. FileSystem.Item
has been replaced by theLocation
protocol, andFileSystem.Item.Kind
has been replaced byLocationKind
.- You can now consistently use either a
name
orpath
when using any API for creating or referring to files and subfolders within a folder. - Methods accepting a
path
now use the simplifiedat:
label, rather thanatPath:
. - External argument labels have been removed for APIs that write new contents to a file. So
write(string:)
andwrite(data:)
are now two overloads of the same method:write(_:)
. - All of the APIs for creating files now only accept
Data
as a file's initial contents. To write strings to a file, first create the file and then callfile.write(string)
on it. File
now has acreationDate
property.Folder
now has static properties for accessing the current user's Library and Documents folders.- Error handling has been improved to now use a unified
FilesError
type, that always contains thepath
at which the error occurred, as well as aReason
- which can either be for locations, writes, or reads. See theLocationError
,WriteError
andReadError
type aliases for the three types of errors that Files can throw. - Computed properties that don't have
O(1)
time complexity have now been changed into methods instead. That includesname()
,count()
, andlast()
on file/folder sequences, since computing those requires enumerating the sequence. The time complexity of each sequence operation is now also documented. FileSystemSequence
is nowFolder.ChildSequence
, and each sequence can now easily be turned into a recursive one by accessing therecursive
property. The same is also true for including hidden files, which is now done by accessing theincludingHidden
property on a sequence. ThemakeFileSequence(...)
andmakeSubfolderSequence(...)
APIs have been removed in favor of constructing customized sequences using those new computed properties.
View build details and download artifacts on buddybuild:
Files (iOS, Files-iOS)