Hey everybody what's going on this is Caleb with slopes dotcom and in this video we're going to set
up an s f Safari view controller to present the repots read me.
It's going to be amazing.
Let's get started by pulling open our project and creating a new group.
OK so select new group type extensions.
Whoops that would be helpful if I was actually typing in the folder.
How about extensions.
Beautiful.
Right click and create a new file.
We're going to go ahead and create a swift file and we're going to call this UI View Controller.
XTi for extension.
And inside of The View Controller extension.
And we're going to create an extension now called extension UI View Controller.
OK.
And this extension is going to allow us to create functions and properties that can be called upon any
instance of you do controller but you'll notice it's not going to like that we are just using foundation.
So I'm going to import you kid kit and you'll notice that air goes away because you have you control
part if you like it it only makes sense.
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
add the read me segment to the end of it and then we're going to create an instance of S.F. Safar View
Controller and present it on the roof View Controller.
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
type string.
And you know what let's actually make this more descriptive present as hefts for our view controller
for u r l k and we're going to go ahead and add the read me u r l.
So let's go ahead and type let read me u r l.
That's going to be basically the U R L plus the read me segment.
If you remember in our Constans file we created this segment that goes at the end of a normal repository
and it basically gives you the ability to show the read me file for that particular repo which is awesome.
So let's go ahead let's minimize the consul there and go back here.
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
l so we should do that from the get go.
So go ahead and let's create an instance of u r l and we're going to use your L string I believe.
And let's go ahead and cut this and paste it in.
And just like that we've got a type of u r l which is beautiful.
So now that we have r u r l we're going to go ahead and create an S.F. Safari view controller.
But if you try to create that right now you're not going to find it because we need to import Safari
services.
So go ahead and import Safari services like so.
And now we can create an instance of S.F. Safari view controller so let's just say let Safari VC equals
S.F. Safari controller.
If you go ahead and instantiate it you can pass in a u r l exactly like so.
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
your L when it's created is actually optional.
So we need to pass it in and force and wrap it.
But it's cool because we know that our laurels are coming in good.
We know that our read me segment is flawless.
And now all we need to do is to call present controller to present is so far AVC animated is true and
completion.
We don't care.
But the thing that we do need to think of is if we try to present this from a table view cell the cell
is not going to know which view controller to present this on top of.
So it's actually not going to work.
What we can do is we can basically call it to present on top of the view controller.
So whatever view controller the table view is a part of we can present it on top of the VC and that's
actually what we're going to do.
But we need to call this function on top of our roof view controller but we don't have access to it
in this extension.
So let's go ahead and let's go to search Fisi.
Now if you remember we just set up our cell here to basically give us the information from a certain
cell tapped on in our table view in our search results.
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
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
to go ahead and pass it in as a type string but it is optional when it comes in.
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
l.
This is literally all it takes to present a sphere of view controller with the read me.
Not joking.
Yeah it's pretty amazing.
Now you might be asking why didn't we have to call the review controller here.
Well because we're already in a controller.
But what is going to be a problem is our trending repo VC.
Remember the cell itself has a button that button has no way of knowing what controller it's on.
So we need to basically access the root VC whenever it is selected.
OK.
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
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.
When we configure the cell we're going to go ahead and just call.
What is the name of the button view read me button are x tap and we're going to go ahead and subscribe.
OK.
And we're going to call on next like we have before like so and you know what.
I put the brackets in the wrong place.
There we go.
All right.
So subscribe on next whenever this is tapped.
We're going to go ahead and call self and this is how we're going to access through visi.
We're going to get the window.
OK which is the receivers window object like it says there.
We're going to go ahead and call the roof view controller on top of that window.
And then on top of the roof controller whatever view controller is holding this cell.
We're going to go ahead and call present Safari VC for you r l.
But you're wondering what you are l the repo u r l of course K supercool.
And you know what just to make sure that we don't have any issues with initialization.
I'm going to put this down here at the bottom.
So whenever the cell is created we set up a subscriber so that basically it's going to present that
controller when we tap on the button.
Now it's asking us to force unwrap it.
So go ahead and do that.
But now no matter what cell we tap on we should get an S.F. Safar view controller.
Let's go try it out build and run.
Let's open it up here in the simulator and oh it's going to yell at us because we're in a closure.
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
not adding it to the Dispose bag so you know what before we move on we need to create an instance of
Dispose bag and do that so our dispose bag equals dispose as bag.
And we need to add it to our dispose bag like so.
All right.
That way we don't have any memory allocation issues and we should be good to go.
Let's go ahead and let's build and run one more time.
Let's go try it out and see how we did.
Case remember no matter if it's this cell or a search sale we should be able to select the read me and
we should be able to go check out the read me file.
So let's try Alamo fire boom S.F. safari of view controller.
Oh so good look at that.
It's right there.
And the cool thing is that an SFR view controller has these buttons built in.
If you want to view it in Safari tap there if you want to reload it tap there if you want to view it
in.
I can't rember what this is called but basically it makes it look super nice do that if you want to
share it do that.
It's all built in.
And the cool thing is if you want to swipe from the left corner you can just swipe to go back.
Now let's try our search function as well.
Our act swiftly search for that.
OK.
Here we go.
And if we tap our swift it loads are swift.
There is our read me so amazingly cool super super super cool guys.
This is awesome.
So it looks like everything is in line.
It looks like we are able to load to reload to select read me's and go view them on the appropriate
page.
This is a good hub client written in our ex-wifes guys.
This is so so cool let's just make sure that when we actually delete everything that it goes back to
nothing.
Beautiful.
Awesome.
Everything is good.
We are amazingly finished with this app I don't know what amazingly finished means but we're finished
guys.
Awesome job completing this arc swift course.
Fantastic work and I can't wait to see what amazing things you build.
Using Eric Swift.
See you guys.