在 F# 中继承多个 类
Inheriting Multiple Classes in F#
我在 Swift 中有以下 class 定义:
class LandlordHome : UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
}
我试图在 F# 中创建它,但是 F# 中的继承模式只允许我继承一个 class,如下所示:
[<Register ("LandlordHome")>]
type LandlordHome (handle:IntPtr) =
inherit UIViewController (handle)
如果我尝试像这样添加额外的 classes:
[<Register ("LandlordHome")>]
type LandlordHome (handle:IntPtr) =
inherit UIViewController, UICollectionViewDelegate, UICollectionViewDataSource (handle)
这会引发错误。
UICollectionViewDelegate
和 UICollectionViewDataSource
不是 class
,而是 protocol
,就像 F#
[= 中的 interface
17=]
所以你的 could 应该看起来像这样(抽象代码):
[<Register ("LandlordHome")>]
type LandlordHome (handle:IntPtr) =
inherit UIViewController (handle)
interface UICollectionViewDelegate with
// implementation of UICollectionViewDelegate
interface UICollectionViewDataSource with
// implementation of UICollectionViewDataSource
我在 Swift 中有以下 class 定义:
class LandlordHome : UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
}
我试图在 F# 中创建它,但是 F# 中的继承模式只允许我继承一个 class,如下所示:
[<Register ("LandlordHome")>]
type LandlordHome (handle:IntPtr) =
inherit UIViewController (handle)
如果我尝试像这样添加额外的 classes:
[<Register ("LandlordHome")>]
type LandlordHome (handle:IntPtr) =
inherit UIViewController, UICollectionViewDelegate, UICollectionViewDataSource (handle)
这会引发错误。
UICollectionViewDelegate
和 UICollectionViewDataSource
不是 class
,而是 protocol
,就像 F#
[= 中的 interface
17=]
所以你的 could 应该看起来像这样(抽象代码):
[<Register ("LandlordHome")>]
type LandlordHome (handle:IntPtr) =
inherit UIViewController (handle)
interface UICollectionViewDelegate with
// implementation of UICollectionViewDelegate
interface UICollectionViewDataSource with
// implementation of UICollectionViewDataSource