1

我正在尝试编写一个propertyWrapper(例如简化),但是当我使用它时,我得到了一个seg fault 11

@propertyWrapper
struct Password {

    private(set) var value: String = ""

    var wrappedValue: String {
        get { value }
        set { value = newValue }
    }

    init(initialValue: String) {
        self.wrappedValue = initialValue
    }
}

当我申请这个结构时,我得到了 seg fault 11

struct AppUserDefaults {
    @Password()
    static var password: String
}

如果我删除static它工作。我不明白为什么我不能在静态变量上使用。propertyWrapper 可以应用于静态查看,我在同一个结构上使用 @UserDefault

4

0 回答 0