What is Swift could not find overload for 'init'?

Asked 2 years ago, Updated 2 years ago, 38 views

if firstRandomNumber>secondRandomNumber{

       playerscoretotal+=1
        self.playerscore.text=String(playerscore)
    }

Now

Could not find an overload for 'init' that acceptance the supplied arguments

The error appears.

Why?

I'm a beginner.

swift

2022-09-30 19:35

3 Answers

Translating the error message freely

Playerscore type cannot be a String() argument

will be

If you want to focus only on the code presented away from the question, I think it's appropriate to rewrite it like this.

if firstRandomNumber>secondRandomNumber{
   playerscoretotal+=1
   self.playerscore.text=playerscore.description
}

Any type implementing the Printable protocol must return some string (String type) and the description must return.


2022-09-30 19:35

The answer to the question is off the subject, but
playerscore.text is substituted with playerscore because of the error.

self.playerscore.text=String(playerscore)

The part of is

self.playerscore.text=String(playerscoretotal)

Isn't that what you are supposed to do?


2022-09-30 19:35

I think that's all right.

self.playerscore.text="\"(playerscore)"


2022-09-30 19:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.