Reputation: 18242
I'm trying to figure out the point of printOn. I've looked through some classes that implement it, and it looks like it just helps to print the units for different datatypes. Is this accurate?
If so, could someone point me in the right direction of how to go about implementing this for my own class? I'm going to be doing arithmetic on potentially different unit sets, and would like to be able to have something like:
4 sec * 2 min = 8 sec min
The implementation to handle these units is complete, but errors keep getting thrown complaining that we have to implement our own printOn:
Upvotes: 3
Views: 1847
Reputation: 2847
The printOn: method is actually intended to be used at development time to show enough information about the object to allow the developer to identify it. This prevents a lot of clicking and diving in inspectors and debuggers. It allows you to click on a variable in a list and see its value displayed in the text pane of the inspector or debugger.
It's not normally used for displaying strings to the end users. The problem there is that strings normally need to be internationalized and mapped into the appropriate language. If you want to display strings to the end user, there are better ways than using printOn:.
Upvotes: 6