簡體   English   中英

是否可以使用私有快速協議?

[英]Are private swift protocols possible?

閱讀有關此文檔后 ,我發現

在Swift中,就像在Objective-C中一樣,協議一致性是全局的-類型不可能在同一程序內以兩種不同方式符合協議。

那么私有前綴的目的是什么

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

class PartyFormViewController: GenericViewController {
    //...
}

在Swift中, private表示:在當前源文件中可見。

私有Type可以符合私有協議,請看這里:

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

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

在這里,“動物和狗”僅在當前文件中可見。 但是,它們被Zoo內部使用,它具有內部可見性,並將動物的數量暴露給整個模塊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM