So imagine Jane, Rob, Marc and Tim come to the playground and make a line in that order. Each with with a picture of an orange, apple, banana, and strawberry, each fruit representing each of them.
I have a photo copier. I go to the from of the line and make two copies of the same first fruit, orange, one for myself (I put it in my pocket, this is the only copy I will make to myself) and make another for Jane, I make also a copy of the next person's fruit, the apple and give both to Jane, so Jane has orange-apple. Go to the next person and make a copy of his fruit and the next person fruit, so Rob has an apple-banana , and Marc has banana-strawberry, etc. Then they all go run around and disperse in the playground. I take the picture of the orange out my pocket and call out for orange, Jane comes running. I say I don't like oranges, and crumble mine and hers oranges pictures, leaving only the apple. I call out apples, and marc comes running with his apple-banana pictures, I say I don't like apples, and crumble the one apple picture. leaving only bananas. I call out bananas and Jim comes running. I destroy the banana, leaving only the strawberry.
So first time around the loop, making a copy of the first orange and keeping it to myself is:
if self.topCardView == nil {
self.topCardView = cardView }
Making the photo copies and handing each person a copy of their fruit and next person card is what the code does in the loop via;
previousCardView?.nextCardView = cardView
previousCardView = cardView
When the view controller shows me the topCard is me looking at the orange in my pocket.
When I swipe left, is me calling out for the oranges person and destroying all the oranges.
She showing the apples is "topCardView=TopCardView.nextCard", meaning the oranges (topCard...) person next fruit (..nextCard)
Me calling out for apples is the view controller showing me the next .
When I swipe left, is me destroying all the apple pictures and the Rob (topCard..) showing next person fruit (...nextCard):
"topCardView=TopCardView.nextCard".
etc.
I think the most important thing is to realize that each time around the loop with
previousCardView?.nextCardView = cardView
previousCardView = cardView
You are not continuously replacing previousCardView unique copy of it, but make a unique copy of it.