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      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.