Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Gimp/libgimpwidgets/   (Gimp Bildeditor Version 3.2.0©)  Datei vom 14.2.2026 mit Größe 2 kB image not shown  

Quelle  UserSettingWrapper.swift   Sprache: JAVA

 

import Foundation
import SwiftUI

/// A property wrapper for user settings that provides both direct and bindable access.
@propertyWrapper
public struct UserSetting<Value> {
    private let keyPath: ReferenceWritableKeyPath<UserSettings, Value>
    private var shouldExit: Bool

    /// Initializes a new instance of the user setting property wrapper.
    /// - Parameters:
    ///   - keyPath: A key path to the specific setting in `UserSettings`.
    ///   - shouldExit: A Boolean value that determines whether the application should exit after setting the value.
    public init(_ keyPath: ReferenceWritableKeyPath<UserSettings, Value>, shouldExit: Bool = false) {
        self.keyPath = keyPath
        self.shouldExit = shouldExit
    }

    /// The current value of the user setting.
    public var wrappedValue: Value {
        get { UserSettings.shared()[keyPath: keyPath] }
        set { UserSettings.shared()[keyPath: keyPath] = newValue }
    }

    /// A bindable version of the user setting that can be used in SwiftUI.
    public var projectedValue: Binding<Value> {
        Binding(
            get: { UserSettings.shared()[keyPath: keyPath] },
            set: { UserSettings.shared()[keyPath: keyPath] = $0
                if shouldExit {
                    exit(1)
                }
            }
        )
    }
}

Messung
CHZG
869010092

¤ Dauer der Verarbeitung: 0.0 Sekunden  (vorverarbeitet am  2026-11-24) ¤

*© Formatika GbR, Deutschland