NEW: Subscribe to Hacking with Swift+ and accelerate your learning! >>

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?

   

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)
      }
 }

   

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.

   

Hacking with Swift is sponsored by Paw

SPONSORED Use Paw to build, test and describe web APIs. Paw has a lightning fast native macOS interface to compose requests, collaborate in real-time on API specs, and generate client code for your applications. You can import and export API definitions.

Discover Paw for Mac

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

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

Not logged in

Log in
 

Link copied to your pasteboard.