将数组传递给 Swift 中的函数抛出无效参数类型错误
Pass an array to a function in Swift throwing invalid parameter type error
这是一个非常基本的问题,但它让我感到困惑...
我正在尝试使用此方法调用函数(在另一个 class 中定义):
var idarray = Profile.getIDArray(Globals.friendlist);
其中 Globals.friendlist 是一个配置文件数组(即 [Profile?] )
现在这是我的 .getIDArray
函数
func getIDArray(inputarray:[Profile?]) -> [String] {
//Blah - code that returns an array of Strings
}
每当我尝试编译它时,我都会收到以下错误:
Cannot invoke 'getIDArray' with an argument list of type '([Profile?])'
这就是我感到困惑的地方 - 因为我很确定我的函数 是 接受 [Profile?] 作为参数类型!
出了什么问题 - swift 中是否引入了我不知道的内容?
您正在调用 getIDArray 作为类型方法。可能您在 func 声明中缺少 class
或 static
关键字:
class func getIDArray(... // if Profile is a class
static func getIDArray(... // if Profile is struct or enum
这是一个非常基本的问题,但它让我感到困惑...
我正在尝试使用此方法调用函数(在另一个 class 中定义):
var idarray = Profile.getIDArray(Globals.friendlist);
其中 Globals.friendlist 是一个配置文件数组(即 [Profile?] )
现在这是我的 .getIDArray
函数func getIDArray(inputarray:[Profile?]) -> [String] {
//Blah - code that returns an array of Strings
}
每当我尝试编译它时,我都会收到以下错误:
Cannot invoke 'getIDArray' with an argument list of type '([Profile?])'
这就是我感到困惑的地方 - 因为我很确定我的函数 是 接受 [Profile?] 作为参数类型!
出了什么问题 - swift 中是否引入了我不知道的内容?
您正在调用 getIDArray 作为类型方法。可能您在 func 声明中缺少 class
或 static
关键字:
class func getIDArray(... // if Profile is a class
static func getIDArray(... // if Profile is struct or enum