|
So, I've been working on the teleporter challenge from UIKit project 26. I've got it set up so that it reads 0-9 as teleporters squares, with the goal of each one going to the next numbered square (with 9 looping back around to 0). Thing is, the numbers aren't necessarily going to be read in order when scanning the map to build it, so simply using If this were PHP, it'd be fairly straightforward:
I think I've found a way to do a similar approach in Swift, but when I'm looping through the array (technically an Here's the code I'm working with, at present
Since we know they're Any suggestions on how to fix it? Thanks in advance! |
|
I'm not sure why you would use And I'm not sure I understand why you are using
Then you can pull the keys and sort them with:
This would also solve the issue of how in |
|
The reason I went with Admittedly, I'd tried the plain Thanks for the tips! |
|
Hello again! Reporting back to let you know that it all came together right away once I figured out how to type the elements of the dictionary when declaring it. I know it seems silly, but type safety has really been the single biggest issue I've had with learning Swift. As you noted, getting the For the benefit of anyone else coming by later who has the same issue, here's the updated class conformed to the recommendations above.
|
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.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.
Link copied to your pasteboard.