Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 460
user1264176 Avatar asked Mar 03 '17 18:03

user1264176


1 Answers

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

like image 90
creeperspeak Avatar answered Oct 11 '22 14:10

creeperspeak