Hey everybody what's going on this is Caleb with slopes dotcom in this video we're going to create a
very simple data service that is going to create a static instance of our particular intent for when
we use Siri and this is going to give us access to this instance throughout our entire application no
matter what class we're in because it is a singleton class.
And like I said it's a static instance that will be available throughout the whole lifecycle of the
application.
And basically when the intent comes in to the app delegate from Siri we're going to go ahead and set
that intent in the data service.
So go ahead and pull open your X code project here and let's get started with that now.
You know what we also should kind of clean up our project here so right click on leg day and create
a controller group and make sure that you spell it properly.
Dragon work out VC.
Go ahead and create what else.
We need a services group because we're creating a data service.
We're going to need an extensions group eventually so we'll just create that now.
And yeah.
So let's go ahead and let's actually let's move that that's not right.
It should be outside of the folder.
There we go and extensions should go down below here.
Awesome.
So there's our view controller our services folders what we care about now.
So right click Create a new file and it can just be a swift file.
OK.
Click next and just call it data service.
I guess we could also call it intense service but data service is fine and what we want to do is create
a class called data service like so and now we create a static instance of our class.
So go ahead and type static let instance equals data service and instantiate it just like that.
Now the reason we're using static.
Like I said is because it enables this instance to stay in memory throughout the entire time that this
app is running.
So it'll never get.
It will never become deallocated.
It's going to stay allocated.
So next in our data service what we need to do is basically create a property to hold an eye and start
work out intent but to do that we're going to need to import intense the Syrie get foundation the framework
I mean.
So type import intense and now type var intent or maybe work out in 10 that might be that might be more
specific.
And that's going to be of type I can start work out intent.
I'm actually going to rename it.
Start work out intent.
So that is now accessible to us anywhere in our app and show you that let's go into the app delegate
and we just created an intent here using the data from user activity passed from Siri kit.
And then what we're going to do is we're going to go ahead and call data service which we need to maybe
build to see that there we go.
Data Service.
Instance.
Intent or start work out intent is going to be equal to intent.
So now our start work out intent is set to the intent that comes from Siri.
So we have access to that everywhere in our application now which is really cool.
The only thing is that we're going to need to send a notification to our view controller to notify it
that the data has been updated.
And that's actually what we're going to do in the next video we're going to handle these results that
are coming back.
We're going to be able to pull out some of the data and we're also going to write a handy little extension
for doubles and it's basically going to take a double value and then convert it into a clock times that
we can display it like you would with a timer.
OK so it will return a string that is like a clock time with the minutes a colon and the seconds at
the end.
So let's head over to the next video and let's set that up.
We're going to handle our data.
We're going to send a notification to our view controller to update our labels.
And we're also going to write a little extension that is going to help us convert our double time into
a clock time.
So let's head over there now and let's get started.