Search code examples
swiftprotocols

Swift. Declaring private functions in internal protocol


How can I achieve something like this (doesn't compile):

internal protocol InternalPrivateMix {
    private func doPrivately()
    internal func doInternaly()
}

Basically I want to kind of make a promise that confirming class implements some functionality privately. This is more for self documentation. I obviously can just implement these functions in my classes without formally conform to protocol and write documentation describing that every class should implement this functionality. Though it would be nice if I could communicate my intent to other developers more formally.

EDIT: I have tried to implement two protocols in one file, one private, one internal as @creeperspeak suggested. However I cannot conform to private protocol in other files so it doesn't work.


Solution

  • From Apple's docs it looks like the only way to achieve what you are trying to do is to implement 2 protocols - one internal, and one private, as Apple states "You cannot set a protocol requirement to a different access level than the protocol it supports."