ios - 私有(private)快速协议(protocol)是否可能?

标签 ios swift syntax

看完docs关于这个我发现

In Swift, as in Objective-C, protocol conformance is global—it is not possible for a type to conform to a protocol in two different ways within the same program.

那么这里私有(private)前缀的作用是什么

private protocol PartyFormViewControllerDelegate: class {
    func partyFormViewController(controller: PartyFormViewController, cancelButtonPressed button: UIBarButtonItem)
}

class PartyFormViewController: GenericViewController {
    //...
}

最佳答案

在 Swift 中,private 表示:在当前源文件中可见。

私有(private) Type 可以符合私有(private)协议(protocol),看这里:

private protocol Animal { }
private class Dog: Animal { }

class Zoo {
    private var animals = [Animal]()
    var count : Int { return animals.count }
}

在这里,Animal 和 Dog 仅在当前文件中可见。但是,它们被 Zoo 使用,它具有内部可见性并将动物的数量公开给整个模块。

关于ios - 私有(private)快速协议(protocol)是否可能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38673619/

相关文章:

javascript - 函数和函数有什么区别

JQuery 清除输入文本字段

ios - 如何将所有背景设置为透明以便可以看到主屏幕?

ios - iOS模拟器没有当前位置吗

swift - CNContactPickerViewController - 无法进行任何选择

ios - swift iOS : How to perform a REST POST request

bash - 为什么模式 "*.so?(.*)"在脚本中而不是在命令行中产生语法错误?

xcode 4.5 - 找不到架构 i386 (zbar) 的符号

ios - ATS 设置 NSAllowsArbitraryLoadsInWebContent 不工作

iOS:增加录制音频的音量