krzysztofzablocki / Sourcery

Meta-programming for Swift, stop writing boilerplate code.
http://merowing.info
MIT License
7.65k stars 616 forks source link

[Question] Register custom @propertyWrapper as Attribute #920

Open m1entus opened 3 years ago

m1entus commented 3 years ago

First of all big up for Sourcery @krzysztofzablocki!

  1. I am wondering if it is possible to register custom @propertyWrapper as Attribute.Identifier type and find them in stencil files ?
  2. Trying to get {% for var in type.variables %} {{ var.type.inherits.UIView }} and check if veriable inherits from UIView, seems type is always nil no matter what, but typeName give me UILabel/UIView is there a reason for that type is nil for variables ?
krzysztofzablocki commented 3 years ago

@m1entus regarding 2. UIView is unknown type so you'd have to use type.based.UIView, you should be getting type property if the types are known to Sourcery (defined in the source it scans), let me know if that's not the case

as for 1 I think you'll get attribute named propertyWrapper and could look into it's arguments to find whatever you are looking for

m1entus commented 3 years ago

Thanks for quick reply!

For the 1 i have defined, where @AccessibilityIdentify is propertyWrapper type and seems there are no results, IBOutlers etc. are working fine but for my custom one i am not getting anything: @AccessibilityIdentify(identifier: "custom_id") var testView = UIView(frame: .zero)

Regardin 2. i have done some workaround and extended UIView with my custom protocol UIViewAccessibilityIdentificable for custom types and checking if hasPrefix UI and seems this is satisfying me for now. {% if var.type.based.UIViewAccessibilityIdentificable or var.typeName|hasPrefix:"UI" %}