sorry I couldn't get the code snippet to work properly. Didn't know how to get it to recognise Swift.
My issue is that I have a class called "Crewman" and I want to generate 25 objects based off of this class within the function "generateCrew". (I am currently trying this in the testing file within Xcode) I don't know how to fix it so that they are all named differently. If I give the objects a specific name then it will just overwrite the first one the next 24 times I run the function.
I am very new to iOS/Swift so would love help... especially as dumbed down for me as possible hahahaha thanks! :D
//This is the class constructor, if thats the right word...
class Crewman {
var name: String!
var navSkill: Int! // #/10
var combatSkill: Int! // #/10
var morale: Int! // #/10
var loyalty: Int! // #/10
}
//This is where I am trying to create the objects within a function
var crewNames =
["Chance", "Bruno", "Toby", "Damien", "Rafael", "Domenic", "Weston", "Edison", "Chris", "Grant", "Cortez", "Darren", "Nicolas", "Everette", "Jason", "Vicente", "Noe", "Ricky", "Ivory", "Thomas", "Guillermo", "Isreal", "Ben", "Winfred", "Lincoln", "Kareem", "Antwan", "Greg", "Lawrence", "Corey", "Todd", "Jeffery", "Rayford", "Julio", "Manual", "Chi", "Bradford", "Devon", "Bryan", "Andreas", "Don", "Erik", "Bobbie", "Tyree", "Felipe", "Clifton", "Carrol", "Kasey", "Cliff", "Jack"]
//Lincoln is no.25
var crewmenAll = [Crewman]()
func generateCrew()
{
for i in 1...25
{
var crewNames[i]:Crewman!
crewmenAll.append(nameOfCrew)
print(crewmenAll)
}
}
override func setUp() {
for i in 1...25
{
let x = Int.random(in: 0..<50)
let name = crewNames[x]
let navInt = Int.random(in: 3...7)
let combatInt = Int.random(in: 3...7)
let moraleInt = Int.random(in: 3...7)
crewmenAll[i] = Crewman(name: name, navSkill: navInt, combatSkill: combatInt, morale: moraleInt, loyalty: 5)
}