How to access the `_` value of a property wrapper that is in another class

Something I noticed today was that I cannot access the type of a property wrapper if its in another scope.

Here's an example:

@propertyWrapper struct MyWrapper<Value> {
    var wrappedValue: Value
    var projectedValue: String {
        "Projected: \(wrappedValue)"
    }

    init(wrappedValue: Value) {
        self.wrappedValue = wrappedValue
    }
}

class MyClass {
    @MyWrapper var wrapper = "Test"

    func foo() {
        print(wrapper) // prints test
        print($wrapper) // prints Projected: test
        print(_wrapper) // prints MyWrapper<Value>
    }
}

class MyOtherClass {
    var myClass = MyClass()

    func foo() {
        print(myClass.wrapper) // prints test
        print(myClass.$wrapper) // prints Projected: test
        print(myClass._wrapper) // '_wrapper' is inaccessible due to 'private' protection level
    }
}

Is this intended behaviour?

Is there any way to expose _wrapper?

It’s meant to be private. But you can write a computed property in MyClass that returns it.

var wrapperStorage: MyWrapper {
  _wrapper
}

then you can do myClass.wrapperStorage.