Thats a good point!

Here is some bikeshedding:

public extension UIViewController {
      
    observe public var view: UIView {
          
        willSet {
            // do something useful here
        }
          
        didSet {
            // do something useful here
        }
    }
}
An extra observe keyword might signal to the compiler the correct intended 
usage.



-- 
Adrian Zubarev
Sent with Airmail

Am 8. Juli 2016 um 13:14:38, Leonardo Pessoa (m...@lmpessoa.com) schrieb:

+1. This would allow us to create observers on any foreign variable. I'm far 
from a compiler right now but I wouldn't this syntax create a new variable 
instead of observing an existing one? Even if not, by reading this one could be 
mislead to believe so. Perhaps you should give it something to differentiate 
from creating a new var, for example by suppressing the type on this 
declaration.

On Friday, 8 July 2016, Adrian Zubarev via swift-evolution 
<swift-evolution@swift.org> wrote:
Hello dear Swift community, I’m not sure if this was discussed before or not, 
but I really want to know if something like this is welcome for the future 
Swift version. If this topic was already discussed, I’m apologizing for 
bringing it back to life in a new thread.

Lets say I’ve got a third party module and I want to know when the a variable 
of some type has changed:

extension UIViewController {
      
    public override var view: UIView {
          
        willSet {
            // do something useful here
        }
          
        didSet {
            // do something useful here
        }
    }
}
Wouldn’t be handy to inject custom didSet and willSet functions into any 
property or computed property?

This would also allow us to build a proper two-way-binding mechanism.



-- 
Adrian Zubarev
Sent with Airmail


--
L
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to