Re: Swift - internal class conforming to public protocol
Re: Swift - internal class conforming to public protocol
- Subject: Re: Swift - internal class conforming to public protocol
- From: Quincey Morris <email@hidden>
- Date: Tue, 24 Nov 2015 23:56:30 -0800
- Feedback-id: 167118m:167118agrif8a:167118sZM49f6qic:SMTPCORP
On Nov 24, 2015, at 23:13 , Marco S Hyman <email@hidden> wrote:
> As I read that adopting a public protocol requires the methods that implement the protocol to be public (but only those methods).
As I said earlier, this isn’t true any more. (I think this change was made in the Swift that was delivered with Xcode 7.0 beta 3, which was released in July.) The following compiles in a playground in Xcode 7.1.1:
> public protocol XP
> {
> func implementMe ();
> }
>
> internal class YC: XP
> {
> internal func implementMe () {}
> }
On Nov 24, 2015, at 22:54 , Andreas Mayer <email@hidden> wrote:
> Also, there are no restrictions in respect to passing parameters. As long as you have access to an entity, you can pass it to someone else; that's your responsibility.
Yes, but if you can’t access the entity’s type declaration (because it’s declared internal or private in another module), then you can't get access to the entity with its actual type. You can only access it via a compatible type that’s public (i.e. a public protocol or superclass), and then you’ll only be able to see the public methods.
> That's explained in "Using Swift with Cocoa and Objective-C":
>
> "The compiler does not automatically insert the @objc attribute for declarations marked with the private access-level modifier.”
That can’t be the full explanation, because the other private method doesn’t produce an error, Roland said.
_______________________________________________
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