【问题标题】:Cannot convert value of type 'String!' to expected argument type error无法转换“字符串!”类型的值到预期的参数类型错误
【发布时间】:2016-01-12 02:44:52
【问题描述】:

我有一个公共功能:

public func lastActivityFor(userName: String) -> String { ... }

后来我想称它为:

OneLastActivity.lastActivityFor("username")

但最后一行出错:

Cannot convert value of type 'String!' to expected argument type 'OneLastActivity'

如果我按照建议发送到那些函数字符串,为什么会出现?(userName: String)

有什么想法可以解决吗?如果您想要更多代码,请询问我。

【问题讨论】:

    标签: ios iphone swift error-handling


    【解决方案1】:

    以这种方式创建你的类的一个实例:

    let temp = OneLastActivity()
    

    现在你可以使用它的方法了:

    temp.lastActivityFor("username")
    

    也可以这样直接使用:

    OneLastActivity().lastActivityFor("username")
    

    希望对你有帮助。

    【讨论】:

    • 哦,我和你同时找到了答案))我用OneLastActivity.sharedInstance.lastActivityFor("username")
    • @DharmeshKheni 先生,请回答这个相关问题,stackoverflow.com/questions/42733225/…
    猜你喜欢
    • 2021-09-18
    • 2019-12-24
    • 2018-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-21
    相关资源
    最近更新 更多