Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.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
Ios 无法转换类型为';绳子';返回预期的参数类型错误_Ios_Iphone_Swift_Error Handling - Fatal编程技术网

Ios 无法转换类型为';绳子';返回预期的参数类型错误

Ios 无法转换类型为';绳子';返回预期的参数类型错误,ios,iphone,swift,error-handling,Ios,Iphone,Swift,Error Handling,我有一个公共职能: public func lastActivityFor(userName: String) -> String { ... } 后来我想称之为: OneLastActivity.lastActivityFor("username") 但最后一行get错误: Cannot convert value of type 'String!' to expected argument type 'OneLastActivity' 如果我按照建议将字符串发送给这些函数,为什么

我有一个公共职能:

public func lastActivityFor(userName: String) -> String { ... }
后来我想称之为:

OneLastActivity.lastActivityFor("username")
但最后一行get错误:

Cannot convert value of type 'String!' to expected argument type 'OneLastActivity'
如果我按照建议将字符串发送给这些函数,为什么会出现此错误?(
userName:String


有什么好主意吗?我怎么修?如果您需要更多代码,请询问我。

只需通过以下方式创建类的实例:

let temp = OneLastActivity()
OneLastActivity().lastActivityFor("username")
现在您可以使用它的方法:

temp.lastActivityFor("username")
或者,您可以通过以下方式直接使用它:

let temp = OneLastActivity()
OneLastActivity().lastActivityFor("username")

希望有帮助。

哦,我和你同时找到了答案)我使用了
OneLastActivity.sharedInstance.lastActivityFor(“用户名”)
@DharmeshKheni先生请回答这个相关问题,