swift-protocols

    6熱度

    2回答

    我有一個使用相關聯的類型的協議,因爲這樣的: protocol Populatable { typealias T func populateWith(object: T) } 並且實現本協議的類: class DateRowType: Populatable { func populateWith(object: NSDate) { print(o

    1熱度

    1回答

    Swift中的詞典不符合ExtensibleCollectionType。因爲它會很容易把它擴大(它在某種程度上不與雨燕1.2的工作;利用斯威夫特2): extension Dictionary: ExtensibleCollectionType { // ignoring this function mutating public func reserveCapacity(

    1熱度

    2回答

    我想指定一個協議來管理符合另一個協議的某些類型的對象。就像這樣: // Specify protocol protocol ElementGenerator { func getElements() -> [Element] } protocol Element { // ... } // Implement class FooElementGenerator:

    2熱度

    1回答

    任務很簡單:我需要創建將所有內容委託給包裝對象的包裝器。只有包裝對象的類型是包含可選方法的協議。我的包裝是實現相同的協議。 我該如何處理可選方法?我可以: 我可以在我的包裝中實現它們。但是,如果它們不是由被封裝的對象實現的,我會從這個實現中返回什麼? 不執行它們。在這種情況下,包裝對象將不會提供我不想要的包裝對象的某些功能。 有沒有更好的選擇?請注意,我在斯威夫特工作。

    1熱度

    1回答

    我想創建一個使用傳統多態性來代替藍牙LE,藍牙等設備的代理,並且似乎無法獲得鑄造的語法權限。 這裏是我的父母協議和類: @objc protocol DeviceDelegate { func didConnectToDevice(name:String) func didFailToConnectToDevice(name:String) func didDisc

    3熱度

    1回答

    我使用的擴展與像類方法的現有類嘗試: @objc public protocol MyProtocol { optional class func foo() -> Int } ,我使用這個協議與通用類似的擴展: extension MyClass { public func bar<T: MyProtocol>() { ... let x: I

    7熱度

    2回答

    Swift有一個類接口的概念,稱爲Protocols。但是我似乎無法找到Swift API中可用的所有協議的完整參考。我在哪裏可以找到所有協議的列表?

    0熱度

    3回答

    我正在Swift中爲iOS創建一個應用程序,並且試圖將我的API調用邏輯保留在我的ViewControllers之外。我跟着this tutorial進行了一個API調用,我將在下面介紹。 我正在創建ViewController將實現的協議「APIControllerProtocol」,然後創建一個APIController類,該類將包含名爲'delegate'的屬性以保存APIControlle

    2熱度

    1回答

    我有以下結構: protocol MidiPlayable : Hashable { var midiValue: UInt8 { get } } struct PercussionSound : MidiPlayable { let name: String let type: PercussionType } struct Note : Hashab