What's New / Storage, System & Virtualization

What's new in System

+33 NewiOS · macOS · tvOS · watchOS · visionOS

System is a Swift interface to operating-system primitives, wrapping POSIX-style file and I/O concepts in typed Swift APIs. The types here cover file metadata: stat records, inodes, file modes, and owner identifiers.

The 27 SDK adds 33 APIs and removes none. New types model file-status metadata: Stat, Inode, FileMode, FileType, FileFlags, DeviceID, and GroupID and UserID for ownership. Several ship nested members: DeviceID.RawValue, FileFlags.RawValue, FileFlags.Element, FileFlags.ArrayLiteralElement (FileFlags conforms to OptionSet and ExpressibleByArrayLiteral), FileMode.RawValue, FileType.RawValue, and a CInterop entry.

New

33
extension

CInterop

NewiOSmacOStvOSvisionOSwatchOS
extension CInterop
Declaration
extension CInterop {

    public typealias DeviceID = dev_t

    public typealias Inode = ino_t

    public typealias UserID = uid_t

    public typealias GroupID = gid_t

    public typealias FileFlags = UInt32
}
struct

DeviceID

NewiOSmacOStvOSvisionOSwatchOS
public struct DeviceID : RawRepresentable, Sendable, Hashable, Codable

A Swift wrapper of the C dev_t type.

Declaration
@frozen public struct DeviceID : RawRepresentable, Sendable, Hashable, Codable {

    /// The raw C `dev_t`.
    public var rawValue: CInterop.DeviceID

    /// Creates a strongly-typed `DeviceID` from the raw C value.
    public init(rawValue: CInterop.DeviceID)

    /// Creates a strongly-typed `DeviceID` from the raw C value.
    public init(_ rawValue: CInterop.DeviceID)

    /// The raw type that can be used to represent all values of the conforming
    /// type.
    ///
    /// Every distinct value of the conforming type has a corresponding unique
    /// value of the `RawValue` type, but there may be values of the `RawValue`
    /// type that don't have a corresponding value of the conforming type.
    @available(anyAppleOS 27.0, *)
    public typealias RawValue = CInterop.DeviceID
}
extension

DeviceID

NewiOSmacOStvOSvisionOSwatchOS
extension DeviceID : BitwiseCopyable
Declaration
extension DeviceID : BitwiseCopyable {
}
struct

FileFlags

NewiOSmacOStvOSvisionOSwatchOS
public struct FileFlags : OptionSet, Sendable, Hashable, Codable

File-specific flags found in the st_flags property of a stat struct or used as input to chflags().

Note: Only available on Darwin, FreeBSD, and OpenBSD.

Declaration
@frozen public struct FileFlags : OptionSet, Sendable, Hashable, Codable {

    /// The raw C flags.
    public let rawValue: CInterop.FileFlags

    /// Creates a strongly-typed `FileFlags` from the raw C value.
    public init(rawValue: CInterop.FileFlags)

    /// Do not dump the file during backups.
    ///
    /// The corresponding C constant is `UF_NODUMP`.
    /// - Note: This flag may be changed by the file owner or superuser.
    public static var noDump: FileFlags { get }

    /// File may not be changed.
    ///
    /// The corresponding C constant is `UF_IMMUTABLE`.
    /// - Note: This flag may be changed by the file owner or superuser.
    public static var userImmutable: FileFlags { get }

    /// Writes to the file may only append.
    ///
    /// The corresponding C constant is `UF_APPEND`.
    /// - Note: This flag may be changed by the file owner or superuser.
    public static var userAppend: FileFlags { get }

    /// File has been archived.
    ///
    /// The corresponding C constant is `SF_ARCHIVED`.
    /// - Note: This flag may only be changed by the superuser.
    public static var archived: FileFlags { get }

    /// File may not be changed.
    ///
    /// The corresponding C constant is `SF_IMMUTABLE`.
    /// - Note: This flag may only be changed by the superuser.
    public static var systemImmutable: FileFlags { get }

    /// Writes to the file may only append.
    ///
    /// The corresponding C constant is `SF_APPEND`.
    /// - Note: This flag may only be changed by the superuser.
    public static var systemAppend: FileFlags { get }

    /// Directory is opaque when viewed through a union mount.
    ///
    /// The corresponding C constant is `UF_OPAQUE`.
    /// - Note: This flag may be changed by the file owner or superuser.
    public static var opaque: FileFlags { get }

    /// File should not be displayed in a GUI.
    ///
    /// The corresponding C constant is `UF_HIDDEN`.
    /// - Note: This flag may be changed by the file owner or superuser.
    public static var hidden: FileFlags { get }

    /// File may not be removed or renamed.
    ///
    /// The corresponding C constant is `SF_NOUNLINK`.
    /// - Note: This flag may only be changed by the superuser.
    public static var systemNoUnlink: FileFlags { get }

    /// File is compressed at the file system level.
    ///
    /// The corresponding C constant is `UF_COMPRESSED`.
    /// - Note: This flag is read-only. Attempting to change it will result in undefined behavior.
    public static var compressed: FileFlags { get }

    /// File is tracked for the purpose of document IDs.
    ///
    /// The corresponding C constant is `UF_TRACKED`.
    /// - Note: This flag may be changed by the file owner or superuser.
    public static var tracked: FileFlags { get }

    /// File requires an entitlement for reading and writing.
    ///
    /// The corresponding C constant is `UF_DATAVAULT`.
    /// - Note: This flag may be changed by the file owner or superuser.
    public static var dataVault: FileFlags { get }

Truncated.

extension

FileFlags

NewiOSmacOStvOSvisionOSwatchOS
extension FileFlags : BitwiseCopyable
Declaration
extension FileFlags : BitwiseCopyable {
}
struct

FileMode

NewiOSmacOStvOSvisionOSwatchOS
public struct FileMode : RawRepresentable, Sendable, Hashable, Codable

A strongly-typed file mode representing a C mode_t.

Note: Only available on Unix-like platforms.

Declaration
@frozen public struct FileMode : RawRepresentable, Sendable, Hashable, Codable {

    /// The raw C mode.
    public var rawValue: CInterop.Mode

    /// Creates a strongly-typed `FileMode` from the raw C value.
    public init(rawValue: CInterop.Mode)

    /// Creates a `FileMode` from the given file type and permissions.
    ///
    /// - Note: This initializer masks the inputs with their respective bit masks.
    public init(type: FileType, permissions: FilePermissions)

    /// The file's type, from the mode's file-type bits.
    ///
    /// Setting this property will mask the `newValue` with the file-type bit mask `S_IFMT`.
    public var type: FileType

    /// The file's permissions, from the mode's permission bits.
    ///
    /// Setting this property will mask the `newValue` with the permissions bit mask `ALLPERMS`.
    public var permissions: FilePermissions

    /// The raw type that can be used to represent all values of the conforming
    /// type.
    ///
    /// Every distinct value of the conforming type has a corresponding unique
    /// value of the `RawValue` type, but there may be values of the `RawValue`
    /// type that don't have a corresponding value of the conforming type.
    @available(anyAppleOS 27.0, *)
    public typealias RawValue = CInterop.Mode
}
extension

FileMode

NewiOSmacOStvOSvisionOSwatchOS
extension FileMode : BitwiseCopyable
Declaration
extension FileMode : BitwiseCopyable {
}
struct

FileType

NewiOSmacOStvOSvisionOSwatchOS
public struct FileType : RawRepresentable, Sendable, Hashable, Codable

A file type matching those contained in a C mode_t.

Note: Only available on Unix-like platforms.

Declaration
@frozen public struct FileType : RawRepresentable, Sendable, Hashable, Codable {

    /// The raw file-type bits from the C mode.
    public var rawValue: CInterop.Mode

    /// Creates a strongly-typed file type from the raw C `mode_t`.
    ///
    /// - Note: This initializer stores the `rawValue` directly and **does not**
    ///   mask the value with `S_IFMT`. If the supplied `rawValue` contains bits
    ///   outside of the `S_IFMT` mask, the resulting `FileType` will not compare
    ///   equal to constants like `.directory` and `.symbolicLink`, which may
    ///   be unexpected.
    ///
    ///   If you're unsure whether the `mode_t` contains bits outside of `S_IFMT`,
    ///   you can use `FileMode(rawValue:)` instead to get a strongly-typed
    ///   `FileMode`, then call `.type` to get the properly masked `FileType`.
    public init(rawValue: CInterop.Mode)

    /// Directory
    ///
    /// The corresponding C constant is `S_IFDIR`.
    public static var directory: FileType { get }

    /// Character special device
    ///
    /// The corresponding C constant is `S_IFCHR`.
    public static var characterSpecial: FileType { get }

    /// Block special device
    ///
    /// The corresponding C constant is `S_IFBLK`.
    public static var blockSpecial: FileType { get }

    /// Regular file
    ///
    /// The corresponding C constant is `S_IFREG`.
    public static var regular: FileType { get }

    /// FIFO (or named pipe)
    ///
    /// The corresponding C constant is `S_IFIFO`.
    public static var fifo: FileType { get }

    /// Symbolic link
    ///
    /// The corresponding C constant is `S_IFLNK`.
    public static var symbolicLink: FileType { get }

    /// Socket
    ///
    /// The corresponding C constant is `S_IFSOCK`.
    public static var socket: FileType { get }

    /// Whiteout file
    ///
    /// The corresponding C constant is `S_IFWHT`.
    public static var whiteout: FileType { get }

    /// The raw type that can be used to represent all values of the conforming
    /// type.
    ///
    /// Every distinct value of the conforming type has a corresponding unique
    /// value of the `RawValue` type, but there may be values of the `RawValue`
    /// type that don't have a corresponding value of the conforming type.
    @available(anyAppleOS 27.0, *)
    public typealias RawValue = CInterop.Mode
}
extension

FileType

NewiOSmacOStvOSvisionOSwatchOS
extension FileType : BitwiseCopyable
Declaration
extension FileType : BitwiseCopyable {
}
struct

GroupID

NewiOSmacOStvOSvisionOSwatchOS
public struct GroupID : RawRepresentable, Sendable, Hashable, Codable

A Swift wrapper of the C gid_t type.

Declaration
@frozen public struct GroupID : RawRepresentable, Sendable, Hashable, Codable {

    /// The raw C `gid_t`.
    public var rawValue: CInterop.GroupID

    /// Creates a strongly-typed `GroupID` from the raw C value.
    public init(rawValue: CInterop.GroupID)

    /// Creates a strongly-typed `GroupID` from the raw C value.
    public init(_ rawValue: CInterop.GroupID)

    /// The raw type that can be used to represent all values of the conforming
    /// type.
    ///
    /// Every distinct value of the conforming type has a corresponding unique
    /// value of the `RawValue` type, but there may be values of the `RawValue`
    /// type that don't have a corresponding value of the conforming type.
    @available(anyAppleOS 27.0, *)
    public typealias RawValue = CInterop.GroupID
}
extension

GroupID

NewiOSmacOStvOSvisionOSwatchOS
extension GroupID : BitwiseCopyable
Declaration
extension GroupID : BitwiseCopyable {
}
struct

Inode

NewiOSmacOStvOSvisionOSwatchOS
public struct Inode : RawRepresentable, Sendable, Hashable, Codable

A Swift wrapper of the C ino_t type.

Declaration
@frozen public struct Inode : RawRepresentable, Sendable, Hashable, Codable {

    /// The raw C `ino_t`.
    public var rawValue: CInterop.Inode

    /// Creates a strongly-typed `Inode` from the raw C value.
    public init(rawValue: CInterop.Inode)

    /// Creates a strongly-typed `Inode` from the raw C value.
    public init(_ rawValue: CInterop.Inode)

    /// The raw type that can be used to represent all values of the conforming
    /// type.
    ///
    /// Every distinct value of the conforming type has a corresponding unique
    /// value of the `RawValue` type, but there may be values of the `RawValue`
    /// type that don't have a corresponding value of the conforming type.
    @available(anyAppleOS 27.0, *)
    public typealias RawValue = CInterop.Inode
}
extension

Inode

NewiOSmacOStvOSvisionOSwatchOS
extension Inode : BitwiseCopyable
Declaration
extension Inode : BitwiseCopyable {
}
struct

Stat

NewiOSmacOStvOSvisionOSwatchOS
public struct Stat : RawRepresentable, Sendable

A Swift wrapper of the C stat struct.

Note: Only available on Unix-like platforms.

Declaration
@frozen public struct Stat : RawRepresentable, Sendable {

    /// The raw C `stat` struct.
    public var rawValue: CInterop.Stat

    /// Creates a Swift `Stat` from the raw C struct.
    public init(rawValue: CInterop.Stat)

    /// Flags representing those passed to `fstatat()`.
    @frozen public struct Flags : OptionSet, Sendable, Hashable, Codable {

        /// The raw C flags.
        public let rawValue: CInt

        /// Creates a strongly-typed `Stat.Flags` from raw C flags.
        public init(rawValue: CInt)

        /// If the path ends with a symbolic link, return information about the link itself.
        ///
        /// The corresponding C constant is `AT_SYMLINK_NOFOLLOW`.
        public static var symlinkNoFollow: Stat.Flags { get }

        /// If the path ends with a symbolic link, return information about the link itself.
        /// If _any_ symbolic link is encountered during path resolution, return an error.
        ///
        /// The corresponding C constant is `AT_SYMLINK_NOFOLLOW_ANY`.
        /// - Note: Only available on Darwin.
        public static var symlinkNoFollowAny: Stat.Flags { get }

        /// If the path does not reside in the hierarchy beneath the starting directory, return an error.
        ///
        /// The corresponding C constant is `AT_RESOLVE_BENEATH`.
        /// - Note: Only available on Darwin and FreeBSD.
        public static var resolveBeneath: Stat.Flags { get }

        /// The type of the elements of an array literal.
        @available(anyAppleOS 27.0, *)
        public typealias ArrayLiteralElement = Stat.Flags

        /// The element type of the option set.
        ///
        /// To inherit all the default implementations from the `OptionSet` protocol,
        /// the `Element` type must be `Self`, the default.
        @available(anyAppleOS 27.0, *)
        public typealias Element = Stat.Flags

        /// The raw type that can be used to represent all values of the conforming
        /// type.
        ///
        /// Every distinct value of the conforming type has a corresponding unique
        /// value of the `RawValue` type, but there may be values of the `RawValue`
        /// type that don't have a corresponding value of the conforming type.
        @available(anyAppleOS 27.0, *)
        public typealias RawValue = CInt
    }

    /// Creates a `Stat` struct from a `FilePath`.
    ///
    /// `followTargetSymlink` determines the behavior if `path` ends with a symbolic link.
    /// By default, `followTargetSymlink` is `true` and this initializer behaves like `stat()`.
    /// If `followTargetSymlink` is set to `false`, this initializer behaves like `lstat()` and
    /// returns information about the symlink itself.
    ///
    /// The corresponding C function is `stat()` or `lstat()` as described above.
    public init(_ path: FilePath, followTargetSymlink: Bool = true, retryOnInterrupt: Bool = true) throws(Errno)

    /// Creates a `Stat` struct from an `UnsafePointer<CChar>` path.
    ///
    /// `followTargetSymlink` determines the behavior if `path` ends with a symbolic link.
    /// By default, `followTargetSymlink` is `true` and this initializer behaves like `stat()`.
    /// If `followTargetSymlink` is set to `false`, this initializer behaves like `lstat()` and
    /// returns information about the symlink itself.
    ///
    /// The corresponding C function is `stat()` or `lstat()` as described above.
    public init(_ path: UnsafePointer<CChar>, followTargetSymlink: Bool = true, retryOnInterrupt: Bool = true) throws(Errno)

    /// Creates a `Stat` struct from a `FileDescriptor`.
    ///
    /// The corresponding C function is `fstat()`.
    public init(_ fd: FileDescriptor, retryOnInterrupt: Bool = true) throws(Errno)

Truncated.

extension

Stat

NewiOSmacOStvOSvisionOSwatchOS
extension Stat : Equatable
Declaration
extension Stat : Equatable {

    /// Returns a Boolean value indicating whether two values are equal.
    ///
    /// Equality is the inverse of inequality. For any values `a` and `b`,
    /// `a == b` implies that `a != b` is `false`.
    ///
    /// - Parameters:
    ///   - lhs: A value to compare.
    ///   - rhs: Another value to compare.
    public static func == (lhs: Stat, rhs: Stat) -> Bool
}
extension

Stat

NewiOSmacOStvOSvisionOSwatchOS
extension Stat : Hashable
Declaration
extension Stat : Hashable {

    /// Hashes the essential components of this value by feeding them into the
    /// given hasher.
    ///
    /// Implement this method to conform to the `Hashable` protocol. The
    /// components used for hashing must be the same as the components compared
    /// in your type's `==` operator implementation. Call `hasher.combine(_:)`
    /// with each of these components.
    ///
    /// - Important: In your implementation of `hash(into:)`,
    ///   don't call `finalize()` on the `hasher` instance provided,
    ///   or replace it with a different instance.
    ///   Doing so may become a compile-time error in the future.
    ///
    /// - Parameter hasher: The hasher to use when combining the components
    ///   of this instance.
    public func hash(into hasher: inout Hasher)

    /// The hash value.
    ///
    /// Hash values are not guaranteed to be equal across different executions of
    /// your program. Do not save hash values to use during a future execution.
    ///
    /// - Important: `hashValue` is deprecated as a `Hashable` requirement. To
    ///   conform to `Hashable`, implement the `hash(into:)` requirement instead.
    ///   The compiler provides an implementation for `hashValue` for you.
    public var hashValue: Int { get }
}
extension

Stat

NewiOSmacOStvOSvisionOSwatchOS
extension Stat : BitwiseCopyable
Declaration
extension Stat : BitwiseCopyable {
}
extension

Stat.Flags

NewiOSmacOStvOSvisionOSwatchOS
extension Stat.Flags : BitwiseCopyable
Declaration
extension Stat.Flags : BitwiseCopyable {
}
struct

UserID

NewiOSmacOStvOSvisionOSwatchOS
public struct UserID : RawRepresentable, Sendable, Hashable, Codable

A Swift wrapper of the C uid_t type.

Declaration
@frozen public struct UserID : RawRepresentable, Sendable, Hashable, Codable {

    /// The raw C `uid_t`.
    public var rawValue: CInterop.UserID

    /// Creates a strongly-typed `UserID` from the raw C value.
    public init(rawValue: CInterop.UserID)

    /// Creates a strongly-typed `UserID` from the raw C value.
    public init(_ rawValue: CInterop.UserID)

    /// The raw type that can be used to represent all values of the conforming
    /// type.
    ///
    /// Every distinct value of the conforming type has a corresponding unique
    /// value of the `RawValue` type, but there may be values of the `RawValue`
    /// type that don't have a corresponding value of the conforming type.
    @available(anyAppleOS 27.0, *)
    public typealias RawValue = CInterop.UserID
}
extension

UserID

NewiOSmacOStvOSvisionOSwatchOS
extension UserID : BitwiseCopyable
Declaration
extension UserID : BitwiseCopyable {
}
typealias

DeviceID.RawValue

NewiOSmacOStvOSvisionOSwatchOS
public typealias RawValue = CInterop.DeviceID

The raw type that can be used to represent all values of the conforming type.

Every distinct value of the conforming type has a corresponding unique value of the RawValue type, but there may be values of the RawValue type that don't have a corresponding value of the conforming type.

typealias

FileFlags.ArrayLiteralElement

NewiOSmacOStvOSvisionOSwatchOS
public typealias ArrayLiteralElement = FileFlags

The type of the elements of an array literal.

typealias

FileFlags.Element

NewiOSmacOStvOSvisionOSwatchOS
public typealias Element = FileFlags

The element type of the option set.

To inherit all the default implementations from the OptionSet protocol, the Element type must be Self, the default.

typealias

FileFlags.RawValue

NewiOSmacOStvOSvisionOSwatchOS
public typealias RawValue = CInterop.FileFlags

The raw type that can be used to represent all values of the conforming type.

Every distinct value of the conforming type has a corresponding unique value of the RawValue type, but there may be values of the RawValue type that don't have a corresponding value of the conforming type.

typealias

FileMode.RawValue

NewiOSmacOStvOSvisionOSwatchOS
public typealias RawValue = CInterop.Mode

The raw type that can be used to represent all values of the conforming type.

Every distinct value of the conforming type has a corresponding unique value of the RawValue type, but there may be values of the RawValue type that don't have a corresponding value of the conforming type.

typealias

FileType.RawValue

NewiOSmacOStvOSvisionOSwatchOS
public typealias RawValue = CInterop.Mode

The raw type that can be used to represent all values of the conforming type.

Every distinct value of the conforming type has a corresponding unique value of the RawValue type, but there may be values of the RawValue type that don't have a corresponding value of the conforming type.

typealias

GroupID.RawValue

NewiOSmacOStvOSvisionOSwatchOS
public typealias RawValue = CInterop.GroupID

The raw type that can be used to represent all values of the conforming type.

Every distinct value of the conforming type has a corresponding unique value of the RawValue type, but there may be values of the RawValue type that don't have a corresponding value of the conforming type.

typealias

Inode.RawValue

NewiOSmacOStvOSvisionOSwatchOS
public typealias RawValue = CInterop.Inode

The raw type that can be used to represent all values of the conforming type.

Every distinct value of the conforming type has a corresponding unique value of the RawValue type, but there may be values of the RawValue type that don't have a corresponding value of the conforming type.

typealias

Stat.RawValue

NewiOSmacOStvOSvisionOSwatchOS
public typealias RawValue = CInterop.Stat

The raw type that can be used to represent all values of the conforming type.

Every distinct value of the conforming type has a corresponding unique value of the RawValue type, but there may be values of the RawValue type that don't have a corresponding value of the conforming type.

typealias

Stat.Flags.ArrayLiteralElement

NewiOSmacOStvOSvisionOSwatchOS
public typealias ArrayLiteralElement = Stat.Flags

The type of the elements of an array literal.

typealias

Stat.Flags.Element

NewiOSmacOStvOSvisionOSwatchOS
public typealias Element = Stat.Flags

The element type of the option set.

To inherit all the default implementations from the OptionSet protocol, the Element type must be Self, the default.

typealias

Stat.Flags.RawValue

NewiOSmacOStvOSvisionOSwatchOS
public typealias RawValue = CInt

The raw type that can be used to represent all values of the conforming type.

Every distinct value of the conforming type has a corresponding unique value of the RawValue type, but there may be values of the RawValue type that don't have a corresponding value of the conforming type.

typealias

UserID.RawValue

NewiOSmacOStvOSvisionOSwatchOS
public typealias RawValue = CInterop.UserID

The raw type that can be used to represent all values of the conforming type.

Every distinct value of the conforming type has a corresponding unique value of the RawValue type, but there may be values of the RawValue type that don't have a corresponding value of the conforming type.

No APIs match your filter.

← More in Storage, System & Virtualization