2
votes

I am following a game tutorial for an iOS app. But there was a version problem, as the tutorial was made with Xcode 8 and swift 3. Im using Xcode 11 and the latest swift version. Anyways, I managed to solve all of the problems that I came across, all accept this one:

        //setup sprites for animation
        _Sprites.append(_Atlas.textureNamed("text"))
        _Sprites.append(_Atlas.textureNamed("text"))
        _Sprites.append(_Atlas.textureNamed("text"))
        _Sprites.append(_Atlas.textureNamed("text"))
        ...

after these lines of code, all of them have the same error: Cannot convert value of type 'SKTexture' to expected argument type 'Int'

I don't know why, because it obviously wants a string(for the name of the sprite), and also, when i try this:

        _Sprites.append(_Atlas.textureNamed(Int("text")))
        ...

It gives me this error: Cannot convert value of type 'Int?' to expected argument type 'String'
Is there anyone who knows why I have this problem?

1
It looked like _Sprites is of type [Int] and not [SKTexture]. - George
thank you that solved it. I declared the sprites as Int instead of string. @ George_E - CoolUserName
Ok, I'll add it as an answer for people in the future experiencing similar problems :) - George

1 Answers

2
votes

It looks like _Sprites is of type [Int] and not [SKTexture]. You are trying to append SKTextures, and as the error says:

Cannot convert value of type 'SKTexture' to expected argument type 'Int'

Meaning that Swift can see that you are trying to set an SKTexture where it expects an Int.


Change your code like so (yours may be slightly different):

_Sprites = [Int]()

to:

_Sprites = [SKTexture]()