Proposal: Stored properties in extensions


(Tomáš Linhart) #1

Hello,

very often, it is necessary to define stored properties in extensions. It
is currently only possible in Swift that has access to ObjC runtime with
associated objects (in theory it might be possible with some global
dictionary) and it requires a lot of boilerplate. Associated objects are
used in UIKit quite heavily so it is something that authors of frameworks
need.

It would be nice to able to create properties in extensions natively in
Swift without need of Objective-C and without a boilerplate. These
properties could be marked with some extra keyword/attribute so it is
obvious they are different and they have a cost (depends on their
implementation).

What do you think?

Tomáš