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 NSSpain

SPONSORED Announcing NSSpain 2020: Remote Edition! An online, continuous conference for iOS developers. We’ll start on Thursday and finish on Friday, with talks, activities, and lots of fun for 36 hours, non-stop. Sound good? Join us!

Find out more

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.