-2

Please help me. I updated to Xcode 10 where is a Swift 4.2. And now format %ld (also others) doesn't work anymore. Who knows what should I use instead that?

let name = String(format: "Pic_%ld", value)

Part of code:

if value != 0 && value != 6 && value != 9 {
    let name = String(format: "Pic_%ld", value)
    print("Pic_%ld")
    print(value)
    let tileNode = SKSpriteNode(imageNamed: name)
    print(name)
    tileNode.size = CGSize(width: Width, height: Height)
    var point = pointFor(column: column, row: row)
    point.x -= Width/2
    point.y -= Height/2
    tileNode.position = point
    tilesLayer.addChild(tileNode)
}

And see that

Pic_%ld
-4
2018-09-23 19:46:52.799361+0800 [20784:2265405] SKTexture: Error loading image resource: "Pic_-4"
Pic_-4
Yury Imashev
  • 2,068
  • 1
  • 18
  • 32

2 Answers2

0

You can format any string by following example .

string =  " \(aNumber) and \(aString)" // wher aNumber is a Int , aString is a string Variable

in you case it should be:

name = "Pic_\(value)"
Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
Return Zero
  • 424
  • 4
  • 15
0

So your code works fine.

// This command prints "Pic_%ld" because there is no formatting, it's just a string
print("Pic_%ld")

// This command prints "-4" because it's the value of the variable 
print(value)

// And these commands prints "Pic_-4". Because your value is -4 
let name = String(format: "Pic_%ld", value)
print(name)

And also you get this error

SKTexture: Error loading image resource: "Pic_-4"

for an obvious reason, there is no such image in your resources. but anyway, String formatting works fine in your case.

Yury Imashev
  • 2,068
  • 1
  • 18
  • 32