Hi
The following code works like a charm. Basically I have this photoArray which I filled with photos during init. In a View I'm iterating through these photos. To do so I added a variable to the ViewController keeping the current ranking (in the array) of the photo. When I want to go to the next photo I'm using the Int returned by the function showNextPhoto in the tuple.
I could change the variable photosArray to [(Int, Photo)] in the Gallery class. The Int indicating the current photo number. In that case I would no longer return a tuple in the nextPhoto function as each photo would have its own ranking. If I would do so it complicates however my code in other parts of my code. So I wondered what you guys would do?
The following code works like a charm. Basically I have this photoArray which I filled with photos during init. In a View I'm iterating through these photos. To do so I added a variable to the ViewController keeping the current ranking (in the array) of the photo. When I want to go to the next photo I'm using the Int returned by the function showNextPhoto in the tuple.
I could change the variable photosArray to [(Int, Photo)] in the Gallery class. The Int indicating the current photo number. In that case I would no longer return a tuple in the nextPhoto function as each photo would have its own ranking. If I would do so it complicates however my code in other parts of my code. So I wondered what you guys would do?
Code:
var photosArray: [Photo] = []
func nextPhoto(var currentPhotoRanking: Int) -> (Int, Photo?) {
if currentPhotoRanking < self.photosArray.count - 1 {
currentPhotoRanking++
} else {
currentPhotoRanking = 0
}
return (currentPhotoRanking, self.photosArray[currentPhotoRanking])
}
Last edited: