Swift 2: 以对象数组为参数调用函数

Swift 2: Call a function using an object array as a parameter

这是我的代码: 我已经有一个名为 "Rooms"

的对象
class BuildRooms  {
func build(room: [Rooms]){
    room[0].setExits([-1,-1,-1,-1])
}

我正在尝试通过键入来使用它:

var room: [Rooms] = []
BuildRooms.build(room)

BuildRooms.build(房间)发生错误 它说:无法将 'Rooms' 类型的值转换为 'BuildRooms'

的预期参数类型

谢谢

您尝试将函数构建调用为 class / 或静态 / 函数,但它被声明为实例函数。我同意,您收到的错误消息可能令人困惑,但它是正确的。

class Rooms {}
class BuildRooms  {
    class func build(room: [Rooms]){
        print("room: \(room)")
    }
}

var room: [Rooms] = []
BuildRooms.build(room) // room: []

你做了什么...可以这样做

class Rooms {}
class BuildRooms  {
    func build(room: [Rooms]){
        print("room: \(room)")
    }
}

var room: [Rooms] = []
let br = BuildRooms()
let bf = BuildRooms.build(br) // here the parameter expected is concrete instance of BuildRooms class and returning type is ...
print(bf.dynamicType) // Array<Rooms> -> ()
bf(room) // room: []