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

Thorsten Seitz tseitz42 at icloud.com
Tue Feb 23 00:10:46 CST 2016

Am 22.02.2016 um 21:38 schrieb Brent Royal-Gordon <brent at architechies.com>:

>>> 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.

I would like to have abstract classes and members in Swift. This is just another place where they turn up and would allow mor consistent declarations.
Other languages do make good use of them and have protocols (interfaces, traits) as well. As long as classes define types abstract members make sense.


> 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