1
00:00:07,550 --> 00:00:12,120
Hey everybody what's going on this is Caleb with slopes dotcom and in this video we're going to set

2
00:00:12,120 --> 00:00:16,640
up an s f Safari view controller to present the repots read me.

3
00:00:16,680 --> 00:00:17,490
It's going to be amazing.

4
00:00:17,490 --> 00:00:22,730
Let's get started by pulling open our project and creating a new group.

5
00:00:22,790 --> 00:00:25,990
OK so select new group type extensions.

6
00:00:26,000 --> 00:00:29,080
Whoops that would be helpful if I was actually typing in the folder.

7
00:00:29,100 --> 00:00:30,770
How about extensions.

8
00:00:30,870 --> 00:00:32,130
Beautiful.

9
00:00:32,130 --> 00:00:34,960
Right click and create a new file.

10
00:00:35,220 --> 00:00:41,360
We're going to go ahead and create a swift file and we're going to call this UI View Controller.

11
00:00:41,500 --> 00:00:43,630
XTi for extension.

12
00:00:44,220 --> 00:00:47,340
And inside of The View Controller extension.

13
00:00:47,370 --> 00:00:53,630
And we're going to create an extension now called extension UI View Controller.

14
00:00:54,220 --> 00:00:54,590
OK.

15
00:00:54,600 --> 00:00:59,700
And this extension is going to allow us to create functions and properties that can be called upon any

16
00:00:59,700 --> 00:01:05,660
instance of you do controller but you'll notice it's not going to like that we are just using foundation.

17
00:01:05,670 --> 00:01:10,310
So I'm going to import you kid kit and you'll notice that air goes away because you have you control

18
00:01:10,430 --> 00:01:12,520
part if you like it it only makes sense.

19
00:01:12,570 --> 00:01:17,670
Now we're going to create a function that will let us pass a u r l n it'll basically take that u r l

20
00:01:18,240 --> 00:01:24,120
add the read me segment to the end of it and then we're going to create an instance of S.F. Safar View

21
00:01:24,120 --> 00:01:28,280
Controller and present it on the roof View Controller.

22
00:01:28,290 --> 00:01:40,230
So go ahead and call phunk present s f Safari v c and like I said we're going to pass in a u r l of

23
00:01:40,230 --> 00:01:40,850
type string.

24
00:01:40,920 --> 00:01:45,300
And you know what let's actually make this more descriptive present as hefts for our view controller

25
00:01:45,330 --> 00:01:50,480
for u r l k and we're going to go ahead and add the read me u r l.

26
00:01:50,490 --> 00:01:54,860
So let's go ahead and type let read me u r l.

27
00:01:54,870 --> 00:02:00,220
That's going to be basically the U R L plus the read me segment.

28
00:02:00,390 --> 00:02:05,970
If you remember in our Constans file we created this segment that goes at the end of a normal repository

29
00:02:06,330 --> 00:02:13,320
and it basically gives you the ability to show the read me file for that particular repo which is awesome.

30
00:02:13,320 --> 00:02:17,280
So let's go ahead let's minimize the consul there and go back here.

31
00:02:17,550 --> 00:02:23,940
So there is r u r l although an S.F. Safar view controller is going to ask for it to be of type u r

32
00:02:23,940 --> 00:02:25,810
l so we should do that from the get go.

33
00:02:25,980 --> 00:02:33,390
So go ahead and let's create an instance of u r l and we're going to use your L string I believe.

34
00:02:33,780 --> 00:02:36,760
And let's go ahead and cut this and paste it in.

35
00:02:37,380 --> 00:02:41,720
And just like that we've got a type of u r l which is beautiful.

36
00:02:41,850 --> 00:02:46,880
So now that we have r u r l we're going to go ahead and create an S.F. Safari view controller.

37
00:02:46,920 --> 00:02:51,690
But if you try to create that right now you're not going to find it because we need to import Safari

38
00:02:51,690 --> 00:02:52,690
services.

39
00:02:52,770 --> 00:02:57,130
So go ahead and import Safari services like so.

40
00:02:57,330 --> 00:03:04,530
And now we can create an instance of S.F. Safari view controller so let's just say let Safari VC equals

41
00:03:04,560 --> 00:03:06,680
S.F. Safari controller.

42
00:03:06,810 --> 00:03:11,250
If you go ahead and instantiate it you can pass in a u r l exactly like so.

43
00:03:11,430 --> 00:03:17,550
So let's pass in the read me u r l and then we're going to need to force on wrap it basically because

44
00:03:18,690 --> 00:03:21,160
your L when it's created is actually optional.

45
00:03:21,180 --> 00:03:23,150
So we need to pass it in and force and wrap it.

46
00:03:23,160 --> 00:03:25,930
But it's cool because we know that our laurels are coming in good.

47
00:03:25,950 --> 00:03:28,680
We know that our read me segment is flawless.

48
00:03:28,680 --> 00:03:38,660
And now all we need to do is to call present controller to present is so far AVC animated is true and

49
00:03:38,660 --> 00:03:39,560
completion.

50
00:03:39,560 --> 00:03:40,580
We don't care.

51
00:03:41,030 --> 00:03:47,030
But the thing that we do need to think of is if we try to present this from a table view cell the cell

52
00:03:47,030 --> 00:03:49,610
is not going to know which view controller to present this on top of.

53
00:03:49,610 --> 00:03:51,250
So it's actually not going to work.

54
00:03:51,290 --> 00:03:57,500
What we can do is we can basically call it to present on top of the view controller.

55
00:03:57,500 --> 00:04:03,590
So whatever view controller the table view is a part of we can present it on top of the VC and that's

56
00:04:03,590 --> 00:04:04,720
actually what we're going to do.

57
00:04:04,730 --> 00:04:10,310
But we need to call this function on top of our roof view controller but we don't have access to it

58
00:04:10,310 --> 00:04:11,080
in this extension.

59
00:04:11,090 --> 00:04:14,300
So let's go ahead and let's go to search Fisi.

60
00:04:14,450 --> 00:04:19,460
Now if you remember we just set up our cell here to basically give us the information from a certain

61
00:04:19,460 --> 00:04:22,710
cell tapped on in our table view in our search results.

62
00:04:22,710 --> 00:04:31,580
So what we can do is we can basically create a u r l here we can go let you r l equals cell dot Ribault

63
00:04:31,580 --> 00:04:36,950
u r l and we're going to force on wrap that because it's coming in as a type string and we're going

64
00:04:36,960 --> 00:04:40,410
to go ahead and pass it in as a type string but it is optional when it comes in.

65
00:04:40,580 --> 00:04:49,870
And then all we have to do is simply call self present S.F. Saffar IVC for u r l and give it the u r

66
00:04:49,870 --> 00:04:50,650
l.

67
00:04:50,740 --> 00:04:55,330
This is literally all it takes to present a sphere of view controller with the read me.

68
00:04:55,550 --> 00:04:56,500
Not joking.

69
00:04:56,500 --> 00:04:58,320
Yeah it's pretty amazing.

70
00:04:58,330 --> 00:05:01,710
Now you might be asking why didn't we have to call the review controller here.

71
00:05:01,900 --> 00:05:04,150
Well because we're already in a controller.

72
00:05:04,240 --> 00:05:08,550
But what is going to be a problem is our trending repo VC.

73
00:05:08,620 --> 00:05:15,970
Remember the cell itself has a button that button has no way of knowing what controller it's on.

74
00:05:15,970 --> 00:05:20,310
So we need to basically access the root VC whenever it is selected.

75
00:05:20,410 --> 00:05:21,020
OK.

76
00:05:21,340 --> 00:05:27,610
And the way we're going to do that is in well let's see if we're going to go ahead and import our swift

77
00:05:27,610 --> 00:05:37,610
here and import Ark's cocoa like so and then let's see if we got to think of a good place to put it.

78
00:05:37,620 --> 00:05:41,860
When we configure the cell we're going to go ahead and just call.

79
00:05:42,210 --> 00:05:49,290
What is the name of the button view read me button are x tap and we're going to go ahead and subscribe.

80
00:05:49,880 --> 00:05:50,530
OK.

81
00:05:50,940 --> 00:05:56,610
And we're going to call on next like we have before like so and you know what.

82
00:05:56,610 --> 00:05:58,230
I put the brackets in the wrong place.

83
00:05:58,230 --> 00:05:59,150
There we go.

84
00:05:59,460 --> 00:05:59,760
All right.

85
00:05:59,760 --> 00:06:02,340
So subscribe on next whenever this is tapped.

86
00:06:02,340 --> 00:06:06,300
We're going to go ahead and call self and this is how we're going to access through visi.

87
00:06:06,300 --> 00:06:07,760
We're going to get the window.

88
00:06:07,840 --> 00:06:11,460
OK which is the receivers window object like it says there.

89
00:06:11,780 --> 00:06:15,650
We're going to go ahead and call the roof view controller on top of that window.

90
00:06:15,900 --> 00:06:19,910
And then on top of the roof controller whatever view controller is holding this cell.

91
00:06:20,040 --> 00:06:23,250
We're going to go ahead and call present Safari VC for you r l.

92
00:06:23,270 --> 00:06:30,870
But you're wondering what you are l the repo u r l of course K supercool.

93
00:06:30,930 --> 00:06:34,650
And you know what just to make sure that we don't have any issues with initialization.

94
00:06:34,650 --> 00:06:36,750
I'm going to put this down here at the bottom.

95
00:06:36,750 --> 00:06:42,470
So whenever the cell is created we set up a subscriber so that basically it's going to present that

96
00:06:42,660 --> 00:06:44,240
controller when we tap on the button.

97
00:06:44,400 --> 00:06:46,500
Now it's asking us to force unwrap it.

98
00:06:46,500 --> 00:06:47,560
So go ahead and do that.

99
00:06:47,790 --> 00:06:52,550
But now no matter what cell we tap on we should get an S.F. Safar view controller.

100
00:06:52,570 --> 00:06:54,890
Let's go try it out build and run.

101
00:06:54,900 --> 00:06:59,720
Let's open it up here in the simulator and oh it's going to yell at us because we're in a closure.

102
00:06:59,730 --> 00:07:05,800
So we need self-doubt repo you are all just like that and oh it's also going to yell at us because we're

103
00:07:05,800 --> 00:07:11,110
not adding it to the Dispose bag so you know what before we move on we need to create an instance of

104
00:07:11,110 --> 00:07:18,760
Dispose bag and do that so our dispose bag equals dispose as bag.

105
00:07:19,480 --> 00:07:23,840
And we need to add it to our dispose bag like so.

106
00:07:24,310 --> 00:07:24,610
All right.

107
00:07:24,610 --> 00:07:30,000
That way we don't have any memory allocation issues and we should be good to go.

108
00:07:30,250 --> 00:07:32,810
Let's go ahead and let's build and run one more time.

109
00:07:32,890 --> 00:07:35,780
Let's go try it out and see how we did.

110
00:07:39,170 --> 00:07:44,840
Case remember no matter if it's this cell or a search sale we should be able to select the read me and

111
00:07:44,840 --> 00:07:46,850
we should be able to go check out the read me file.

112
00:07:46,850 --> 00:07:51,830
So let's try Alamo fire boom S.F. safari of view controller.

113
00:07:51,850 --> 00:07:53,110
Oh so good look at that.

114
00:07:53,120 --> 00:07:54,820
It's right there.

115
00:07:54,820 --> 00:07:58,140
And the cool thing is that an SFR view controller has these buttons built in.

116
00:07:58,140 --> 00:08:02,280
If you want to view it in Safari tap there if you want to reload it tap there if you want to view it

117
00:08:02,610 --> 00:08:03,030
in.

118
00:08:03,060 --> 00:08:08,130
I can't rember what this is called but basically it makes it look super nice do that if you want to

119
00:08:08,130 --> 00:08:09,390
share it do that.

120
00:08:09,390 --> 00:08:10,400
It's all built in.

121
00:08:10,410 --> 00:08:14,370
And the cool thing is if you want to swipe from the left corner you can just swipe to go back.

122
00:08:14,370 --> 00:08:16,290
Now let's try our search function as well.

123
00:08:16,290 --> 00:08:18,620
Our act swiftly search for that.

124
00:08:19,100 --> 00:08:19,400
OK.

125
00:08:19,400 --> 00:08:20,050
Here we go.

126
00:08:20,070 --> 00:08:24,620
And if we tap our swift it loads are swift.

127
00:08:24,620 --> 00:08:30,530
There is our read me so amazingly cool super super super cool guys.

128
00:08:30,530 --> 00:08:31,990
This is awesome.

129
00:08:32,000 --> 00:08:34,880
So it looks like everything is in line.

130
00:08:34,880 --> 00:08:42,350
It looks like we are able to load to reload to select read me's and go view them on the appropriate

131
00:08:42,670 --> 00:08:43,770
page.

132
00:08:43,780 --> 00:08:46,580
This is a good hub client written in our ex-wifes guys.

133
00:08:46,580 --> 00:08:52,370
This is so so cool let's just make sure that when we actually delete everything that it goes back to

134
00:08:52,370 --> 00:08:53,020
nothing.

135
00:08:53,330 --> 00:08:54,020
Beautiful.

136
00:08:54,230 --> 00:08:55,080
Awesome.

137
00:08:55,090 --> 00:08:56,100
Everything is good.

138
00:08:56,240 --> 00:09:00,890
We are amazingly finished with this app I don't know what amazingly finished means but we're finished

139
00:09:00,890 --> 00:09:01,620
guys.

140
00:09:01,700 --> 00:09:04,420
Awesome job completing this arc swift course.

141
00:09:04,520 --> 00:09:07,820
Fantastic work and I can't wait to see what amazing things you build.

142
00:09:07,820 --> 00:09:09,130
Using Eric Swift.

143
00:09:09,200 --> 00:09:09,680
See you guys.
