Reputation: 59
I’m trying to code a game in swift and I want to be able to keep track of enemy position, Heath, and such. Like in Java it’s as easy as declaring an array list of type, say, enemy and then filling it with a forloop or when ever I want to add an enemy. But I’ve looked absolutely everywhere for help on the subject and I’m not finding what I need for my game to work. Any help would be much appreciated. Thank you so much!
Upvotes: 0
Views: 1207
Reputation: 247
Swift has collections just like Java. You could create an array of the objects, like so:
var someInts = [Int]()
someInts.append(3)
Using the example, change Int
for the type of the enemy object. You would then need to iterate using a for loop to retrieve (or store) any more objects.
More information on Swift collections are here (also includes how to iterate through them):
Upvotes: 2