Xcode 无法将字符串类型的值转换为预期的参数类型soundex
我刚刚编写了一个名为Xcode 无法将字符串类型的值转换为预期的参数类型soundex,xcode,swift,macos,Xcode,Swift,Macos,我刚刚编写了一个名为compute的函数,它接受一个字符串并将其转换为soundex值。但是,当我调用该函数时,它给出了一个错误,即无法将“String”类型的值转换为预期的参数类型“Soundex”。我不确定这里发生了什么,但我认为这与我没有在Soundex类中正确声明函数有关 斯威夫特 import Cocoa class Soundex { func compute(word: String) -> String { return _compute(wor
compute
的函数,它接受一个字符串并将其转换为soundex值。但是,当我调用该函数时,它给出了一个错误,即无法将“String”类型的值转换为预期的参数类型“Soundex”
。我不确定这里发生了什么,但我认为这与我没有在Soundex
类中正确声明函数有关
斯威夫特
import Cocoa
class Soundex {
func compute(word: String) -> String {
return _compute(word, length: 4)
}
func _compute(word: String, length: Int) -> String {
...
}
}
ViewController.swift
var lastName: String = lastNameText.stringValue
lastName = Soundex.compute(lastName) //get error on this line
任何帮助都会很棒,谢谢 使用Soundex.compute(lastName)
调用一个类方法。但是compute(:)
不是类方法。将方法更改为:
class func compute(word: String) -> String {
...
}
使用Soundex.compute(lastName)
调用一个类方法。但是compute(:)
不是类方法。将方法更改为:
class func compute(word: String) -> String {
...
}
我将其更改为
class func compute
,但现在我在调用中得到了错误额外的参数“length”
。我已将函数的其余部分添加到我的原始帖子中。您只能从类方法调用类方法。我将其更改为class func compute
,但现在我在调用中得到了错误额外参数“length”。我已将函数的其余部分添加到我的原始帖子中。您只能从类方法调用类方法。