prepareForReuse()💪
Prepares a reusable cell for reuse by the table view’s delegate.
Apple docs says just this about this unsung hero but I feel people are should know more about this guy. Few days back I came across a bug which made me come across this method.
First I had done the clean up in this way —
But as you can see that this code doesn’t look like 😍 because I am cleaning up before even setting up so then I tried to find a place where I could clean my cell up and then came across our guy.
Now this piece of code is beautiful!!! Because now set up and clean up process separate. Now cell reusability is clean. Just keep in mind that the element where only content changes(like label’s text) don’t do anything for them here, that will be handled in cellForRowAt:
.
Happy coding
The sooner you start coding, the longer it takes.