1 00:00:01,120 --> 00:00:01,160 "Redo: Better printing with printOn:" 2 00:00:01,880 --> 00:00:01,920 Quentin Ducasse. 3 00:00:03,040 --> 00:00:03,880 -Hello, everyone. 4 00:00:04,200 --> 00:00:06,320 In part 6 of the redo, 5 00:00:06,640 --> 00:00:10,840 we will see how to change the output the "Print it" command gave us. 6 00:00:11,160 --> 00:00:14,400 For now, we will look at the Counter object we created, 7 00:00:14,720 --> 00:00:17,000 if we remove the "increment" and print everything. 8 00:00:17,320 --> 00:00:21,880 So, double-click, right-click, Print it or we can simply press Cmd+P. 9 00:00:22,840 --> 00:00:25,280 We can see that it is a counter 10 00:00:25,600 --> 00:00:28,440 but we do not have much info on the value it holds 11 00:00:28,760 --> 00:00:30,000 and this might be valuable. 12 00:00:30,680 --> 00:00:31,880 In order to change that, 13 00:00:32,200 --> 00:00:35,800 we have to take a look at the printOn method. 14 00:00:36,120 --> 00:00:39,160 Let's go there and write the "printOn:" 15 00:00:39,520 --> 00:00:43,280 so it takes "aStream" as an argument and... 16 00:00:43,840 --> 00:00:49,360 We want to keep the Counter we had before. 17 00:00:49,680 --> 00:00:52,520 So, this is a Counter. 18 00:00:53,240 --> 00:00:57,200 But we want to add value. 19 00:00:57,880 --> 00:01:04,480 We have to do : "aStream nextPutAll:". 20 00:01:05,720 --> 00:01:09,040 And we have to add "withValue" 21 00:01:10,200 --> 00:01:14,440 and in order to concatenate two strings, we will use the comma 22 00:01:15,200 --> 00:01:16,280 and then write "count" 23 00:01:16,600 --> 00:01:19,800 and convert for count to a string with "printString". 24 00:01:20,320 --> 00:01:21,920 This is a counter, 25 00:01:22,480 --> 00:01:23,880 this is "withValue", 26 00:01:24,200 --> 00:01:28,440 and this will add the actual value of "count" to a string. 27 00:01:28,760 --> 00:01:29,520 And now, 28 00:01:30,520 --> 00:01:33,000 we will add a carriage return. 29 00:01:34,280 --> 00:01:36,400 Let's save all this 30 00:01:36,840 --> 00:01:38,960 and see how it works now. 31 00:01:39,480 --> 00:01:43,360 We should have a Counter with value 0, right? 32 00:01:43,800 --> 00:01:44,840 Let's print it. 33 00:01:45,160 --> 00:01:47,320 "Counter withValue 0". That is great. 34 00:01:47,640 --> 00:01:52,160 Now, if we change this, and make it start at 23, 35 00:01:52,920 --> 00:01:53,880 and print this, 36 00:01:54,600 --> 00:01:56,920 "Counter withValue 23". So, that is cool. 37 00:01:57,680 --> 00:02:01,640 That is working as expected and it is a good time to commit what we changed. 38 00:02:01,960 --> 00:02:03,120 Let's go to Commit, 39 00:02:03,440 --> 00:02:07,160 say: "printOn method corrected 40 00:02:09,400 --> 00:02:10,480 (with value)". 41 00:02:12,520 --> 00:02:14,040 And let's commit everything. 42 00:02:14,680 --> 00:02:16,280 So, in this part, 43 00:02:16,600 --> 00:02:20,000 we learned how to change the output we can get with a "Print it" command 44 00:02:20,320 --> 00:02:22,320 on an object we have defined.