在F#中继承多个类

问题描述 投票:1回答:1

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

这会引发错误。

swift inheritance f# uicollectionview superclass
1个回答
5
投票

UICollectionViewDelegateUICollectionViewDataSource不是classes,但protocols,就像interface中的F#s

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

[<Register ("LandlordHome")>]
type LandlordHome (handle:IntPtr) =
    inherit UIViewController (handle)
    interface UICollectionViewDelegate with
       // implementation of UICollectionViewDelegate
    interface UICollectionViewDataSource with
       // implementation of UICollectionViewDataSource
© www.soinside.com 2019 - 2024. All rights reserved.