Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a public function:

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

and later I want to call it as:

OneLastActivity.lastActivityFor("username")

but the last line get error:

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

Why it appears if I send to those function String as suggested?(userName: String)

Any ideas how can I fix it? If you want more code, just ask me about.

like image 447
Orkhan Alizade Avatar asked Mar 14 '26 07:03

Orkhan Alizade


1 Answers

Just create an instance of your class this way:

let temp = OneLastActivity()

Now you can use it's method:

temp.lastActivityFor("username")

Or you can directly use it this way:

OneLastActivity().lastActivityFor("username")

Hope it helps.

like image 177
Dharmesh Kheni Avatar answered Mar 16 '26 23:03

Dharmesh Kheni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!