Login
You're viewing the assemblag.es public feed.
  • Aug 28, 2025, 11:46 AM

    #Swift Bug or feature:

    EDIT: This is what `ReferenceWritableKeyPath` is for. Thanks, @calicoding!

    struct GenericWrapper<Item: AnyObject, Value> {
    let property: WritableKeyPath<Item, Value>
    let object: Item

    func commit(newValue: Value) {
    object[keyPath: property] = newValue // error: `let` mimimi
    var stfu = object
    stfu[keyPath: property] = newValue // properly works because `Item` is a reference type after all, and the compiler knows, but pretends not to?!
    }

    💬 0🔄 1⭐ 0