1
00:00:00,380 --> 00:00:06,090
So will come back again in this exercise you are supposed to rewrite the code we did in our previous

2
00:00:06,090 --> 00:00:10,330
lesson which was swift and redo it again you know Objective C.

3
00:00:10,390 --> 00:00:15,540
Now this is one of those exercises that they really encourage you to attempt it on your own simply because

4
00:00:15,900 --> 00:00:20,240
doing delegation even though in terms of the concept is exactly the same thing.

5
00:00:20,270 --> 00:00:25,650
Blade has some of the stuff that you know you may not really grasp in the very first attempt and doing

6
00:00:25,650 --> 00:00:32,370
them once in Objective C is going to show you some you know some more insights into using them and coding

7
00:00:32,370 --> 00:00:32,680
it.

8
00:00:32,790 --> 00:00:35,450
So I really encourage you to actually try it on your own.

9
00:00:35,460 --> 00:00:38,010
I'm going to pause the video now for a few seconds.

10
00:00:38,010 --> 00:00:43,920
This is the time for you to pause entirely and try it on your own and then come back to the code and

11
00:00:43,920 --> 00:00:50,600
the solution that I have and show to compare it with what you have the.

12
00:00:50,640 --> 00:00:52,200
So let's get started.

13
00:00:52,200 --> 00:00:59,280
In the interest of saving time I've actually made parts of my application already I've made my interface

14
00:00:59,280 --> 00:01:02,120
builder the Baden's I've made my segue.

15
00:01:02,220 --> 00:01:05,510
I have connected all these different you know outlets.

16
00:01:05,520 --> 00:01:13,640
So in my view controller I have a label received message but I have a call to action in my view contorted

17
00:01:13,680 --> 00:01:18,260
and I have to program the body of this method in my view controller.

18
00:01:18,270 --> 00:01:21,410
I have the textfield and I have a go back action.

19
00:01:21,420 --> 00:01:24,900
And of course I have to program the body of this one.

20
00:01:24,990 --> 00:01:27,550
So let's first get the things we know out of the way.

21
00:01:27,600 --> 00:01:34,590
In my view toward that end I'm going to go ahead and say import the green of your controller and you

22
00:01:34,590 --> 00:01:36,540
might go to with green action.

23
00:01:36,570 --> 00:01:44,480
I'm going to say self performs Segway performs Segway with identifier on the identifier.

24
00:01:44,480 --> 00:01:48,440
I gave it was called Green Segway ID.

25
00:01:48,650 --> 00:01:50,470
I have no senders.

26
00:01:50,610 --> 00:01:52,670
So that's one part of the problem.

27
00:01:52,860 --> 00:01:58,710
The other part obviously is the preparation some going to say void prepare for Segway.

28
00:01:58,830 --> 00:02:04,090
And again you could check for the sake of the identifier or you could skip it just like what I'm doing.

29
00:02:04,290 --> 00:02:12,480
I'm going to say green View Controller Green an instance is going to be Segway our destination view

30
00:02:12,500 --> 00:02:15,020
controller and that's about that.

31
00:02:15,030 --> 00:02:23,740
So so far we managed to prepare our getting in stance and we also got our Segway to be performed.

32
00:02:23,940 --> 00:02:27,690
Now I'm going to go to Green view controller on the go back action.

33
00:02:27,750 --> 00:02:37,670
I'm going to get emesis drink let's say text or send that is going to be the name of my textfield the

34
00:02:37,670 --> 00:02:39,170
DOT to text.

35
00:02:39,240 --> 00:02:45,750
Obviously the value in it I'm going to store it and then I'm going to say self this mystery controller

36
00:02:46,200 --> 00:02:47,420
animated.

37
00:02:47,530 --> 00:02:48,690
True.

38
00:02:49,110 --> 00:02:51,000
And I don't want to do anything.

39
00:02:51,070 --> 00:02:52,160
It's completion.

40
00:02:52,200 --> 00:02:53,390
Perfect.

41
00:02:53,400 --> 00:02:57,900
So we got this far and by now we should be able to launch an application.

42
00:02:57,900 --> 00:03:03,960
It should be you know managed to go from one viewpoint or to the other one and do the basic stuff just

43
00:03:03,960 --> 00:03:08,010
the way that we expected it in here.

44
00:03:08,010 --> 00:03:13,950
I could go ahead and say go to Green go perfect.

45
00:03:13,970 --> 00:03:18,980
So the next thing we need to do is we need to add the protocol to our application so to do that we can

46
00:03:19,070 --> 00:03:24,950
either introduce your protocol inside the body of one of your data files or you could do it the way

47
00:03:25,010 --> 00:03:32,690
I personally like to do and that's adding in new data h find someone to say command and here is a header

48
00:03:32,690 --> 00:03:37,150
file and this other file I'm going to call it put a can remember protocols.

49
00:03:37,140 --> 00:03:44,450
They don't have any logic so all they have is actually the body of their declaration and because their

50
00:03:44,470 --> 00:03:48,940
declaration they are like interfaces so they are data aitches header files.

51
00:03:49,110 --> 00:03:55,520
So I'm actually going to say import and I have to import the foundations simply because without the

52
00:03:55,520 --> 00:03:58,010
foundation there isn't really much we can do.

53
00:03:58,070 --> 00:04:08,030
The next thing is say at protocol and my protocol is going to be called sending mass sage protocol and

54
00:04:08,030 --> 00:04:13,280
this thing that you see in here it essentially means that the sending masses for the core conforms to

55
00:04:13,430 --> 00:04:15,080
this object itself.

56
00:04:15,080 --> 00:04:16,880
This is actually an optional thing.

57
00:04:16,880 --> 00:04:22,960
You could if you wanted to remove it and the only method I have in it is this voice.

58
00:04:23,390 --> 00:04:33,260
And it sends a just call send and the send is actually a and has a string on that and assisting is called

59
00:04:33,800 --> 00:04:36,860
message just like what we had last time.

60
00:04:36,860 --> 00:04:44,420
Now as you might very well remember from our swift example one of these two view controllers view controller

61
00:04:44,490 --> 00:04:46,930
that h n m not degree in one.

62
00:04:47,000 --> 00:04:49,900
They have to conform to that protocol.

63
00:04:50,000 --> 00:04:52,340
And the other one should use the protocol.

64
00:04:52,340 --> 00:04:54,330
So first this can conform to it.

65
00:04:54,380 --> 00:05:02,840
And when I was at that stage I'm going to say let's first import whether re-importing protocol import

66
00:05:02,870 --> 00:05:03,500
protocol.

67
00:05:03,590 --> 00:05:08,010
And then my view controller is a subclass of viewpoint.

68
00:05:08,060 --> 00:05:12,120
And it also conforms to sending message protocol.

69
00:05:12,140 --> 00:05:18,890
Now that I have it conforming to a sending message protocol I have to be including those methods which

70
00:05:18,890 --> 00:05:26,300
is essentially this one in the body of my implementation which is in my data and so it might that ominous

71
00:05:26,390 --> 00:05:28,900
one is going to give me an error in itself.

72
00:05:29,030 --> 00:05:34,110
I have to add that when I go in here and say well this one is in here.

73
00:05:34,190 --> 00:05:45,080
So whenever somebody calls send from the delegates who are delegating to you being called the view controller

74
00:05:45,420 --> 00:05:52,940
this function should run and if this function does run I'm going to say received Laymon that text should

75
00:05:52,940 --> 00:05:58,070
become whatever we receive just like the last time that we had done that.

76
00:05:58,070 --> 00:06:04,250
Now the other thing that we had to do was we had to go through Grandview contorted and say hey this

77
00:06:04,250 --> 00:06:14,120
one is using the Send the message protocol as a very old outcome but to say at property and that property

78
00:06:14,120 --> 00:06:23,990
is going to be non atomic and is going to be of the type i.e. the Veach does conform to what does it

79
00:06:23,990 --> 00:06:28,200
conform to sending message protocol which I have to import it.

80
00:06:28,520 --> 00:06:38,270
I'm going to say import protocols and it is going to be sending Nassir protocol and I'm calling delegates.

81
00:06:38,360 --> 00:06:39,660
So what is this.

82
00:06:39,660 --> 00:06:46,930
This line is essentially the one that we had in the swift which was our delegate of the times sending

83
00:06:46,970 --> 00:06:53,850
message delegate that was that and we have it in here as a property which is this what exactly.

84
00:06:53,960 --> 00:06:59,490
And that property since we don't know its type we're going up with doesn't the objective.

85
00:06:59,530 --> 00:07:03,760
Are saying that this is an idea which does conform to this.

86
00:07:03,830 --> 00:07:06,580
It is called of course delegate and it is non-atomic.

87
00:07:06,740 --> 00:07:12,440
We'll talk more about the atomic non-atomic and retain and sign at the end of this section.

88
00:07:12,440 --> 00:07:16,210
So keep this one for now the way it is now.

89
00:07:16,340 --> 00:07:17,870
I have that property.

90
00:07:18,020 --> 00:07:24,230
And the next thing I could do is I could go to my viewpoint or that am saying when you make the union

91
00:07:24,230 --> 00:07:33,440
stance do you agree any stance that delegates to self so delegate tasks from this one to here.

92
00:07:33,680 --> 00:07:36,050
Here being my view controller.

93
00:07:36,260 --> 00:07:43,670
And finally in my viewpoint for that am I'm going to go ahead and say every time you're going back do

94
00:07:44,790 --> 00:07:50,240
self delegate send what you want to send.

95
00:07:50,240 --> 00:07:53,720
I want to send this particular text.

96
00:07:53,930 --> 00:07:59,780
This is exactly identical to what we did for swithe is exactly the same thing but the return objective

97
00:07:59,790 --> 00:08:04,290
c when we're going back we get the delegate and we use its method.

98
00:08:04,370 --> 00:08:07,130
We send the something doesn't matter what that thing is.

99
00:08:07,130 --> 00:08:14,210
It is the one in the text which you know View Controller Vicki form to this particular protocol which

100
00:08:14,210 --> 00:08:22,070
means it's methods most notably this one should be activated in here it should have a function body

101
00:08:22,070 --> 00:08:26,660
in here the body of it is get the message up within the label.

102
00:08:26,870 --> 00:08:33,800
And finally in here we are saying that when you're preparing for say what you want to do is you want

103
00:08:33,800 --> 00:08:40,580
to say this new one the new instance then it gets to here being the View Controller.

104
00:08:40,910 --> 00:08:49,110
So I'll go around this and if all goes well go to Green Hello from green.

105
00:08:49,270 --> 00:08:51,770
And it says hello from doing.

106
00:08:52,190 --> 00:08:53,260
And that's about that.

107
00:08:53,300 --> 00:09:02,470
Using protocols and delegation patterns in both the iOS 4 of its swift and I was with Objective-C.

108
00:09:02,630 --> 00:09:04,710
Let's keep that in mind in the next lesson.

109
00:09:04,710 --> 00:09:10,640
We're going to move into something that is using an existing delegation from one of four athletes.
