【问题标题】:Inheriting Multiple Classes in F#在 F# 中继承多个类
【发布时间】:2018-06-08 23:39:59
【问题描述】:

我在 Swift 中有以下类定义:

class LandlordHome : UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {

}

我正在尝试在 F# 中创建它,但是 F# 中的继承模式只允许我像这样继承一个类:

[<Register ("LandlordHome")>]
type LandlordHome (handle:IntPtr) =
inherit UIViewController (handle)

如果我尝试像这样添加其他类:

[<Register ("LandlordHome")>]
type LandlordHome (handle:IntPtr) =
inherit UIViewController, UICollectionViewDelegate, UICollectionViewDataSource (handle)

这会引发错误。

【问题讨论】:

  • 我没有使用 F# 的经验。但请注意,LandlordHome 继承自 single 类 UIViewController,并符合其他协议。

标签: swift inheritance f# uicollectionview superclass


【解决方案1】:

UICollectionViewDelegateUICollectionViewDataSource不是classes,而是protocols,就像F#中的interfaces一样

所以你的可能看起来应该是这样的(抽象代码):

[<Register ("LandlordHome")>]
type LandlordHome (handle:IntPtr) =
    inherit UIViewController (handle)
    interface UICollectionViewDelegate with
       // implementation of UICollectionViewDelegate
    interface UICollectionViewDataSource with
       // implementation of UICollectionViewDataSource

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-19
    • 1970-01-01
    • 2010-11-08
    • 2013-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多