迅速.在内部协议中声明私有函数 [英] Swift. Declaring private functions in internal protocol

查看:52
本文介绍了迅速.在内部协议中声明私有函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能实现这样的东西(不编译):

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.

我试图在一个文件中实现两种协议,一种是私有的,一种是内部的,正如@creeperspeak 所建议的那样.但是我不能在其他文件中符合私有协议,所以它不起作用.

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.

推荐答案

从 Apple 的文档 看来,实现您正在尝试做的事情的唯一方法是实现 2 种协议 - 一种是内部协议,一种是私有协议,正如 Apple 所说:您不能将协议要求设置为不同的访问级别比它支持的协议."

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

这篇关于迅速.在内部协议中声明私有函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆