NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

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 Essential Developer

SPONSORED From January 26th to 31st you can join a FREE crash course for iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a senior developer!

Save your 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.