在F#中继承多个类

时间:2017-12-28 12:05:51

标签: swift inheritance f# uicollectionview superclass

我在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)

这会引发错误。

1 个答案:

答案 0 :(得分:5)

UICollectionViewDelegateUICollectionViewDataSource不是class es,而是protocol s,就像interface中的F#

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

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