Let's say that I have the following Struct:
struct LogInfo {
var logNumber: Int
var species: String
var diameter: Float
var formClass: Int
var numLogs: Float
var boardFootage: Double
}
And it is populated by the following:
var logInfoArray = [LogInfo]()
logInfoArray.append(LogInfo(logNumber: 1, species: "Spruce", diameter: 18.0, formClass: 78, numLogs: 1.5, boardFootage: 110.0))
logInfoArray.append(LogInfo(logNumber: 2, species: "Spruce", diameter: 17.0, formClass: 78, numLogs: 1.0, boardFootage: 90.0))
logInfoArray.append(LogInfo(logNumber: 3, species: "Pine", diameter: 18.0, formClass: 78, numLogs: 1.5, boardFootage: 89.0))
logInfoArray.append(LogInfo(logNumber: 4, species: "Pine", diameter: 21.0, formClass: 78, numLogs: 1.0, boardFootage: 120.0))
logInfoArray.append(LogInfo(logNumber: 5, species: "Pine", diameter: 19.0, formClass: 78, numLogs: 1.5, boardFootage: 200.0))
logInfoArray.append(LogInfo(logNumber: 6, species: "Oak", diameter: 22.0, formClass: 78, numLogs: 2, boardFootage: 180.0))
How would I go about performing some array functions on these entries?
For example - I would like figure out how many unique species are in the array, and end up with a new array containing each individual species.
i.e. var speciesArray = ["Spruce", "Pine", "Oak"]
I would also like to be able to then perform some calculations with those in mind. Like, tallying up the total board footage values of all entries that have "Pine" as the species.
Does anybody have some tips on how I could go about this?
Thank you in advance!
logInfoArray = [LogInfo(...), LogInfo(...), ... LogInfo(...)]) than to make a mutable array to which you repeatedly append.