I am wondering what is best when I want some functions to be publicly accessible and some internal to the protocol.
I am writing an AudioManager in Swift 3 wrapping AVPlayer as a frame.
I want some methods to be public, so for example, a ViewController using AudioManager can access some methods, but some methods will not be displayed outside the box
β i.e. have access modifier internal instead of public .
I am writing a framework with a protocol design, almost every part should have a protocol.
So the protocols speak with the protocols within. the main class - AudioManager - has AudioPlayer and should be able to call some internal functions on it, for example, pause(reason:) , but this method should be internal and not shown out of the box.
Here is an example.
internal enum PauseReason { case byUser case routeChange }
I know that I can make it work by changing the pauseBecauseOfRouteChange method to look like this:
func pauseBecauseOfRouteChange() { guard let internalPlayer = audioPlayer as? InternalAudioPlayerProtocol else { return } internalPlayer.pause(reason: .routeChange) }
But I wonder if there is a more elegant solution?
Something like labeling that AudioPlayerProtocol clarifies InternalAudioPlayerProtocol ...
Or how do your fellow programmers do it?
A frame is more beautiful if it does not disclose methods and variables intended for internal use!
Thanks!
source share