cannot convert value of type UIImage to expected argument type string

13,483

Solution 1

Maybe I'm missing something but why are you adding this?

#imageLiteral(resourceName: 

The correct syntax is

let ground = SKSpriteNode(imageNamed: "Ground")

Solution 2

I was doing :

profileImgView.image = UIImage(named: #imageLiteral(resourceName: "default_UserImage"))

while it should be :

profileImgView.image = #imageLiteral(resourceName: "default_UserImage")

imageLiteral already return UIImage.

Share:
13,483

Related videos on Youtube

Gh0st
Author by

Gh0st

Updated on June 04, 2022

Comments

  • Gh0st
    Gh0st almost 2 years

    I have some problem with swift.

    Ground = SKSpriteNode(imageNamed: "#imageLiteral(resourceName: "Ground")")
    

    Here it says "cannot convert value of type UIImage to expected argument type string" how can i fix this

  • Gh0st
    Gh0st almost 8 years
    I'm trying to get the "Ground" picture on the bottom of the screen when i do 'let' or 'string' it tells me to add a ; and no matter how many i type it always wants one more. That code is inside override func didMove(to view: SKView) and i got a var Ground = SKSpriteNode() inside class GameScene: SKScene { All i did was start a Game project in Xcode and i only wrote that so far.
  • Gh0st
    Gh0st almost 8 years
    So i was selecting the img when i used that line of code i copied yours next to mine and the only difference was that yours wasn't selecting any img thank you fixed the problem