Re: access modifiers in protocols
Re: access modifiers in protocols
- Subject: Re: access modifiers in protocols
- From: Roland King <email@hidden>
- Date: Wed, 17 Jun 2015 13:37:56 +0800
> On 17 Jun 2015, at 13:33, Quincey Morris <email@hidden> wrote:
>
> On Jun 16, 2015, at 22:24 , Roland King <email@hidden <mailto:email@hidden>> wrote:
>>
>> 1) making FooImplementedWithArray internal downgrades the foo() function to internal within that protocol, no longer is it public (this is made explicit by a compiler warning which tells you you’re implementing an internal function as public if you try doing it)
>> 2) anything implementing FooImplementedWithArray can at *most* be internal, you can’t have a public class implement an internal protocol
>
> What about this:
>
>> public protocol Foo
>> {
>> mutating func foo( Int )->Void
>> }
>>
>> public protocol FooImplementedWithArray : Foo
>> {
>> }
>>
>> extension FooImplementedWithArray
>> {
>> var bar = Array<Int> ()
>> public mutating func foo( i : Int ) -> Void { bar.append( i ) }
>> }
>
> Then Foo’s that don’t use a bar array will provide their own implementation, and FooImplementedWithArray’s will default to the extension’s empty array, or they can override bar with some other implementation. At least, that’s what it looks like to me. :)
>
> Sorry if you said that already. In your explanation, I can’t seem to separate what you want from what you’ve tried.
>
No - can’t have a stored property in an extension
var bar = Array<Int>() // <— nope
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden