swift-protocols

    0熱度

    1回答

    我正在使用傳統的Swift 2.2項目,並且我想爲我的代碼實現一些衆所周知的面向協議的實踐。 protocol SuccessPresenting { func presentSucess(title: String, message: String) } extension SuccessPresenting where Self: UIViewController {

    2熱度

    3回答

    我有一個泛型類的形式爲: class BaseClass<T> { var prop: T ... } 我然後有形式的多個子類: class SubClassOne: BaseClass<SomeSubClass> { ... } class SubClassTwo: BaseClass<SomeOtherSubClass> { ... }

    0熱度

    1回答

    我使用的tableview數據源的擴展,如下所示。我想在我的應用程序中將此擴展應用於多個tableview控制器。我看不到任何簡單的方法來允許單個通用擴展擴展多個類,而不會複製&將相同的代碼粘貼到不同的單獨擴展中。可能的解決方案是定義一個protocol,然後擴展該協議。在這些情況下,然而它們被定義的協議,然後擴展功能自定義函數而在tableview中的數據源擴展我想申請到許多類,函數是覆蓋標準的

    0熱度

    1回答

    我實現如下組成結構: protocol ProtocolA { func doStuff() } protocol ProtocolB { } extension ProtocolA { func doStuff() { print("From protocol A") } } extension ProtocolA where Self:

    0熱度

    3回答

    我已經在迅速上創建類和類和它的協議。我正在使用的OBJ-C啓用的項目,但我得到以下錯誤,而編譯我的項目。 找不到'SpeechRecognizerDelegate'的協議聲明; 你的意思是'SFSpeechRecognizerDelegate'? 任何人都可以指導我如何在我的Obj-C類中使用Swift類協議。 這裏是我的銀行代碼:在的OBJ-C protocol SpeechRecognizer

    0熱度

    1回答

    我正在爲我的核心數據模型設計數據管理器,並且想創建一個通用函數來獲取類的親屬。 我已經創建了一個協議,允許爲每種數據類型構建管理器。在這個協議中,我已經定義了兩個相關的類型T和K以及幾個簡單的函數。現在我被一個類親戚抓取方法卡住了 - 我需要指出T有K個親戚。我妄圖創建一些協議,通過相互的屬性來表示這種關係,所以這兩個類都可以符合這個協議。任何想法,甚至有可能嗎? import Foundatio

    2熱度

    2回答

    我有一個Equatable類 class Item: Equatable { var value: AnyObject? var title: String init(title: String, value: AnyObject?) { self.title = title self.value = value } //E

    1熱度

    2回答

    是否可以在另一協議的通用功能中提供確認協議? 我試着讓它像這樣工作,但這是不可能的,或者我犯了一些錯誤。 我的代碼: protocol DataModelProtocol { associatedtype ObjectProtocol: Protocol func fetchObjects<T: ObjectProtocol>() -> [T]? func fetch

    0熱度

    1回答

    我安裝了一個吊艙Material和莢有這樣的事情: extension UIViewController: UIViewControllerTransitioningDelegate { //here is the method to conform protocol } 但我需要我自己的貼合在同一個地方的協議: 當我嘗試致以UIViewController與UIViewContr

    0熱度

    2回答

    我從框架 public protocol BaseMappable { /// This function is where all variable mappings should occur. It is executed by Mapper during the mapping (serialization and deserialization) process. mu