Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 无法将字符串类型的值转换为预期的参数类型soundex_Xcode_Swift_Macos - Fatal编程技术网

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”。我已将函数的其余部分添加到我的原始帖子中。您只能从类方法调用类方法。