<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On May 8, 2016, at 10:33 AM, Karl Wagner via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 4 May 2016, at 00:46, Aleksandar Petrovic via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hi swift-evolution,<br class=""><br class="">I want to apologize in advance for my clumsy English. It's (obviously) not my first language.<br class=""><br class="">Recent discussion about property behaviours reminded me of function decorators in Python. I think decorators can nicely fit in Swift, too.<br class=""><br class="">First, a bit of explanation for the uninitiated. Decorator is a function that transform other function - it receives some function and returns a function of the same signature. Lets make some dead simple decorator:<br class=""></div></div></blockquote></div></div></div></blockquote></div><br class=""><div class=""><br class=""></div><div class=""><div class="">In Objective-C, you can add a category that will entirely replace an existing method. Could using decorators allow us to add behaviors to methods to extend their behavior without overwriting those methods? Here is an example of what I'm thinking.</div><div class=""><br class=""></div><div class="">extension UIView {</div><div class=""> decorate func somethingElse(...) {</div><div class=""> // performs existing behavior of somethingElse</div><div class=""> ... adds new behavior ...</div><div class=""> }</div><div class="">}</div><div class=""><br class=""></div><div class="">Context: I was asking about whether this kind of "extend rather than replace or subclass" behavior were possible in Swift, and was told that "decorators" might be the right technology to implement it.</div><div class=""><br class=""></div><div class="">Thanks in advance for any insight.</div><div class=""><br class=""></div><div class="">-- E</div><div class=""><br class=""></div><div><blockquote type="cite" class=""></blockquote></div></div></body></html>