UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

DiveIntoSpriteKit Project 4

Forums > Swift

Hi, I'm a little stuck on this part where “The last step for our grid is to call createItem() once for each item in our grid. ”

   for x in 0 ..< itemsPerRow {
        var col = [Item]()
    }
    for y in 0 ..< itemsPerColumn
    {
        let item = createItem(row: y, col: x)
        col.append(col)
    }

“ put this code at the end of didMove(to:):” I did this in GameScene.swift

After I did this step, I find that the x and the col are not declared. Am I missing a step to declare those or am I putting this in the wrong spot?

2      

Hi, you need to nest the second loop inside the first one like so:

 for x in 0 ..< itemsPerRow {
      var col = [Item]()

      for y in 0 ..< itemsPerColumn
      {
          let item = createItem(row: y, col: x)
          col.append(col)
      }
 }

2      

Hey @nemecek-filip thanks for that but the x is still undeclared? Is it implicitly declared with the For?

Using this now i have a "Missing argument label 'contentsOf:' in call" error instead which I'm confused about.

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.