Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to support @propertyWrapper? #97

Open
bigearsenal opened this issue Aug 14, 2021 · 1 comment
Open

Is it possible to support @propertyWrapper? #97

bigearsenal opened this issue Aug 14, 2021 · 1 comment

Comments

@bigearsenal
Copy link
Contributor

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 bigearsenal changed the title Is it possible to support @propertyWrapper Is it possible to support @propertyWrapper? Aug 14, 2021
@wickwirew
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants