[swift-evolution] [Review] SE-0030 Property Behaviors

Brent Royal-Gordon brent at architechies.com
Mon Feb 22 19:13:29 CST 2016


(Resending due to the issue with the lists this afternoon.)

>> I don't think "abstract" is the right keyword to use, but I do agree that "accessor" might not be the perfect term for this feature. Not sure what would be better, though.
> 
> Why? "abstract" is quite common for denoting a method requirement, so I think it is quite appropriate here.

Except in Swift, which has no abstract members at all; it instead leaves that job to protocols.

Unfortunately, constructing an analogy to protocols doesn't give you a good keyword to use. `protocol` won't do, because that's the name for the whole, not the parts. The individual parts are called requirements, but the `required` keyword actually serves a different role, and it would be misleading here because many accessors are defaulted.

Actually, if I had to pick a word, it might be "delegate". This is essentially a delegation pattern: we're calling back into the type applying the property to ask it what to do. Call the block a property delegate:

	@json var foo: Foo? {
		// This thing is now the "property delegate"
		toJSON {
			// This is a "delegate method"
			return value.json
		}
		fromJSON {
			// So is this
			return Foo(JSON: json)
		}
	}

And then mark each method to be provided by it with the `delegate` keyword:

	delegate toJSON(value: Value) -> JSONValue
	delegate fromJSON(json: JSONValue) -> Value
	// Or
	delegate func toJSON(value: Value) -> JSONValue
	delegate func fromJSON(json: JSONValue) -> Value

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list