associated-types

    0热度

    1回答

    嘿,我得到了ConfigurationType协议 protocol ConfigurationType {} 和我自己的细胞类 class ConfigurableCell<T: ConfigurationType>: UITableViewCell { func configure(with config: T) {} } 我所有的细胞ConfigurableCell继承,

    1热度

    1回答

    鉴于此协议: import Foundation protocol Updatable { associatedtype E func updateValuesWith(_ newElement: E) } 实施这一项目: private func update<T: NSObject>(_ values: inout [T], with newValues: [T

    1热度

    2回答

    是否可以在另一协议的通用功能中提供确认协议? 我试着让它像这样工作,但这是不可能的,或者我犯了一些错误。 我的代码: protocol DataModelProtocol { associatedtype ObjectProtocol: Protocol func fetchObjects<T: ObjectProtocol>() -> [T]? func fetch

    -1热度

    1回答

    我试图做一个元组类型有一个Hashable项目&任何项目,&在字典的自定义初始化程序中使用它。但是,Swift不会以这种方式使用Hashable,&我被卡住了。我不想将我可以创建的字典限制为仅使用字符串作为键。 protocol CollectionInitializeable { associatedtype T init(items: [T]) } extension

    3热度

    1回答

    我想要一个'通用'地图数据结构,它可以通过提供自定义实例来高效地进行专门化,就像在the GHC manual section on type families中一样。 {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} module

    0热度

    1回答

    我做了一个虚拟项目来测试泛型和相关类型。 这是一个协议 protocol WordProto : Equatable { // BTW not sure if I should put Equatable here associatedtype WordAlias : Equatable // or here var homonyms: [WordAlias] { get

    0热度

    1回答

    我一直在尝试做一些代码,允许用户“附加”到特定单元格的特定模型。我打算通过协议和associatedType方法来做到这一点。 这里的计划: 细胞符合MTZSectionRowConfigurable时,他们可以显示数据,但他们不一定需要: public protocol MTZSectionRowConfigurable { associatedtype T: MTZSectionRo

    0热度

    1回答

    我在操场上写了一些示例代码,并希望函数返回两个值之间的距离,这两个值符合Swift中的Strideable协议,以便我可以使用distance(to other: Self) -> Self.Stride功能。我的执行情况如下: func distanceFrom<T: Strideable, U>(_ a: T, to b: T) -> U where T.Stride == U {

    0热度

    1回答

    我仍然在学习如何使用相关类型实现协议的对象数组。 我有以下协议: public protocol Word : Equatable, Hashable { // compiles associatedtype WordType : Equatable var moreWords: [WordType] { get } } public protocol WordDa

    0热度

    1回答

    我有一个Game类。我说它是通用的,因为我需要支持不同类型的电路板。现在我只想添加一个经典的iOS风格的委托,其方法是将一个游戏和一个新的积分值作为参数。如何在Swift associatedtype的方式实现这一点?我很困惑,我无法推动这种简单的逻辑。 protocol GamePointsDelegate { associatedtype B: Board func gam