What's New / Storage, System & Virtualization

What's new in StateReporting

+3 NewiOS · macOS · tvOS · watchOS

StateReporting is a framework for describing the reportable state of system components as structured metadata keys and values.

The 27 SDK adds 3 APIs, with no deprecations or removals. The new types are the ReportableMetadata protocol and the ReportableMetadataValue enum, plus a Never conformance. ReportableMetadata defines what a type contributes as reportable metadata, and ReportableMetadataValue models the value side.

New

3
extension

Never

NewiOSmacOStvOSwatchOS
extension Never : ReportableMetadata

Extension to make Never conform to ReportableMetadata for cases where no metadata is needed

Declaration
extension Never : ReportableMetadata {

    /// A dictionary mapping string keys to reportable values that describes the current metadata.
    public var metadataDictionary: [String : ReportableMetadataValue] { get }
}
protocol

ReportableMetadata

NewiOSmacOStvOSwatchOS
public protocol ReportableMetadata

A protocol for types that can supply their metadata as a dictionary of reportable values.

Adopt ReportableMetadata to pass stable or volatile metadata to StateReporter. The single required property, metadataDictionary, maps string keys to ReportableMetadataValue cases. Use the ReportableMetadata() macro to synthesize the conformance automatically from stored properties, rather than implementing it by hand.

Declaration
public protocol ReportableMetadata {

    /// A dictionary mapping string keys to reportable values that describes the current metadata.
    var metadataDictionary: [String : ReportableMetadataValue] { get }
}
enum

ReportableMetadataValue

NewiOSmacOStvOSwatchOS
public enum ReportableMetadataValue : Sendable, Codable, Hashable

A value in a reportable-metadata dictionary.

Strings, numbers, and dates all initialize directly. The ReportableMetadata() macro constructs these automatically when you annotate your metadata type.

let values: [String: ReportableMetadataValue] = [
    "username": ReportableMetadataValue("alice"),
    "loginCount": ReportableMetadataValue(42),
    "lastLogin": ReportableMetadataValue(Date()),
    "score": ReportableMetadataValue(98.6)
]
Declaration
public enum ReportableMetadataValue : Sendable, Codable, Hashable {

    case date(Date)

    case string(String)

    case integer(Int128)

    case floatingPoint(Double)

    public init(_ value: String)

    public init(_ value: Date)

    public init(_ value: Int)

    public init(_ value: Int8)

    public init(_ value: Int16)

    public init(_ value: Int32)

    public init(_ value: Int64)

    public init(_ value: Bool)

    public init(_ value: UInt)

    public init(_ value: UInt8)

    public init(_ value: UInt16)

    public init(_ value: UInt32)

    public init(_ value: UInt64)

    public init(_ value: Float)

    public init(_ value: Double)

    public init(_ value: CGFloat)

    /// Encodes this value into the given encoder.
    ///
    /// If the value fails to encode anything, `encoder` will encode an empty
    /// keyed container in its place.
    ///
    /// This function throws an error if any values are invalid for the given
    /// encoder's format.
    ///
    /// - Parameter encoder: The encoder to write data to.
    public func encode(to encoder: any Encoder) throws

    /// Creates a new instance by decoding from the given decoder.
    ///
    /// This initializer throws an error if reading from the decoder fails, or
    /// if the data read is corrupted or otherwise invalid.
    ///
    /// - Parameter decoder: The decoder to read data from.
    public init(from decoder: any Decoder) throws

    /// 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 == (a: ReportableMetadataValue, b: ReportableMetadataValue) -> Bool

    /// 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:)`,

Truncated.

No APIs match your filter.

← More in Storage, System & Virtualization