[swift-evolution] [Proposal] Property behaviors

Brent Royal-Gordon brent at architechies.com
Mon Dec 21 14:31:40 CST 2015


I've been thinking a little more about the usage. If you don't want to do the @ thing, suppose you instead use a behavior by specifying it in the block:

	var foo: Bar {
		lazy { Bar() }	// This property will be lazy, and initialized/re-iniitalized with this block
		synchronized	// This property will be synchronized (you could provide a block to give a queue, but the default's fine here)
		logged		// Calls are logged
	}

You might only be able to specify one closure per behavior, so willSet and didSet would have to be different behaviors, but I don't think that's necessarily a bad thing—it'd be nice if `observable` could be saved for arbitrary third-party observation (that is, a KVO replacement).

It's even possible that you could implement `get` and `set` themselves as behaviors! That would be pretty neat.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list