我在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)
这会引发错误。
答案 0 :(得分:5)
UICollectionViewDelegate
和UICollectionViewDataSource
不是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