Swift. Declaring private functions in internal protocol

前端 未结 2 1475
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-13 02:34

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

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


        
相关标签:
2条回答
  • 2021-01-13 02:59

    You can do this:

    protocol P {
        func int()
    }
    
    extension P {
        func int() {
            print("int()")
            priv()
        }
        private func priv() {
            print("priv()")
        }
    }
    

    Which might serve your purpose - I use it.

    0 讨论(0)
  • 2021-01-13 03:11

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

    0 讨论(0)
提交回复
热议问题