<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">I try to avoid using inheritance for just adding functionality - for that I use (and love) extensions.</div><div class="">This works great for functions - but I find the lack for stored properties support limiting.</div><div class=""><br class=""></div><div class="">Here’s my use case:</div><div class="">I want to map every textfield in my view controller to a JSON field - so it would be very helpful to add a string <i class="">Key</i> property to all of the UITextFields in my app.</div><div class="">For now this is how I solve this issue (inside the extension):</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><font face="HelveticaNeue" class=""><i class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> customProperties {</span></i></font></div></div><i class=""><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">static</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">var</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class=""> key : </span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">String</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">?</span><br class=""><span style="font-family: HelveticaNeue;" class="">}</span><br class=""><span class="Apple-tab-span" style="font-family: HelveticaNeue; white-space: pre;">        </span><br class=""><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">var</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class=""> key : </span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">String</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">? {</span></i><div class=""><i class=""><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>get</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class=""> {</span><br class=""><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span></span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">return</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">objc_getAssociatedObject</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">self</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">, &</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">customProperties</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">.key) </span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">as</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">? </span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">String</span><br class=""><span class="Apple-tab-span" style="font-family: HelveticaNeue; white-space: pre;">        </span><span style="font-family: HelveticaNeue;" class="">}</span><br class=""><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">set</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class=""> (value){</span><br class=""><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span></span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">objc_setAssociatedObject</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">self</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">,&</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">customProperties</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">.key,value,.</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">OBJC_ASSOCIATION_RETAIN_NONATOMIC</span><span style="font-family: HelveticaNeue; font-variant-ligatures: no-common-ligatures;" class="">)</span><br class=""><span class="Apple-tab-span" style="font-family: HelveticaNeue; white-space: pre;">        </span><span style="font-family: HelveticaNeue;" class="">}</span><br class=""></i><div class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font face="HelveticaNeue" class=""><i class="">}</i></font></span></div></div></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font face="HelveticaNeue" class=""><i class=""><br class=""></i></font></span></div><div style="margin: 0px; line-height: normal;" class=""><font face="HelveticaNeue" class="">I would love to just add an actual variable to the extension without the need to use Obj-C associated objects.</font></div></body></html>