无法将string类型的值转换为预期的参数类型soundex

时间:2015-11-22 06:15:48

标签: xcode swift macos

我刚刚编写了这个名为compute的函数,它接受一个字符串并将其转换为soundex值。当我调用该函数时,它会给出一个错误Cannot convert value of type 'String' to expected argument type 'Soundex'。我不确定这里发生了什么,但我认为这与我在Soundex类中没有正确声明函数有关。

Soundex.swift

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

任何帮助都会很棒,谢谢!

1 个答案:

答案 0 :(得分:5)

使用Soundex.compute(lastName)调用类方法。但compute(_:)不是一种类方法。将方法更改为:

class func compute(word: String) -> String {
    ...
}