Protocol Variable Implementing Another Protocol

How to use multiple protocols in Swift with same protocol variables?

The simple answer is that you can't.

Maybe one protocol depends on another, in which case you would use the dependent protocol for the type of your delegate.

How to create a Protocol in a Package without requiring Variables to be implemented Public?

You cannot do that.

If you make a type conform to a protocol, the conform will have the same access identifiers as the type itself. So if you make a public type conform to a protocol, the protocol conformance will be public as well.

In order for a type to conform to a protocol, all protocol requirements must be met. And if you are able to refer to a type as the protocol it conforms to, you must be able to access all protocol requirements as well.
So if you declare a type public and make it conform to a protocol, you must declare all protocol requirements (both properties and methods) as public.

This is by design and you cannot get around it.



Related Topics



Leave a reply



Submit