-1

Because I already read document of Apple and stackoverflow I understand why we use prepareForReuse method.

However I don't understand why we add super.prepareForReuse() to prepareForReuse().

I guess it is very basic knowledge about Swift, so i did google hard. But I can't understand about that. Please help me. Thank you.

doori
  • 85
  • 1
  • 6

1 Answers1

1

Simple answer: because Apple says so. The documentation says:

If you override this method, you must be sure to invoke the superclass implementation

That means call super. Just do it. Clearly the UITableViewCell class itself does something in its implementation of prepareForReuse, and Apple is telling you to make sure it gets to do that.

That's all there is to say about the matter, because Cocoa is closed source. You cannot see what UITableViewCell does. And you shouldn't care. Just do what Apple tells you. That is how to use the Cocoa framework.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Oh, I got it. Thanks for the great answer. – doori Aug 07 '20 at 12:43
  • No problem. This is just the price we pay for using a closed framework. You just have to pay attention to the docs, because they are the only way of knowing what the rules are. You might be able to deduce by experimentation what can go wrong if you fail to call `super`, but then again you might not, and it's really not worth the effort. – matt Aug 07 '20 at 13:11