Runtime icon indicating copy to clipboard operation
Runtime copied to clipboard

Is it possible to support @propertyWrapper?

Open bigearsenal opened this issue 4 years ago • 1 comments

Hi there! Thanks for an awesome library! Lately I faced the problem with @propertyWrapper. I have tried to create a @propertyWrapper:

@propertyWrapper public struct Blob {
    public init(length: Int) {
        self.length = length
        self.wrappedValue = []
    }
    
    let length: Int
    
    public var wrappedValue: [UInt8]
}

Then I used it in my struct just like this one:

struct MyStruct {
  @Blob(length: 10) var blob: [UInt8]
  ...
}

And then I tried to createInstance , i got length = 0, I could not create instance with default length (=10). How to reflect the propertyWrapper and get the default length (= 10)? Thanks

bigearsenal avatar Aug 14 '21 12:08 bigearsenal

So unfortunately this isn't possible. createInstance doesn't work by calling an initializer. It just allocates the memory manually and sets each field to a default value, which for an Int is 0

wickwirew avatar Aug 17 '21 17:08 wickwirew