So I'm trying to store the average vote on images in an array (each value for each image is stored respectively.)
Here's what happens: The user votes, the average of the votes is shown to the user (from past votes), and then the user taps "next" to move onto the next movie to vote on.
How would I go about storing the value of each image so that it has its own average stored? I'm pretty new to swift...
Here's the function with which I'm calculating the average and the global variable above it which holds the array of the votes:
var votes:[Double] = []
func average(nums:[Double]) ->Double {
var total = 0.0
for vote in nums {
total += Double(vote)
}
let votesTotal = Double(nums.count)
var average = total/votesTotal
return average
}
I'm accessing the images through incrementing (only 10). This is in an UIButton normally.
The counter variable is outside of the scope of the IBAction where the counter increment is being performed.
var counter = 1
(IBACTION)
counter++
if counter == 10 {
counter = 1
}
imageOfPerson.image = UIImage(named:"image\(counter).jpg")
resultLabel.text = ""
enableButtons()
}
Thanks a lot in advance.