1
00:00:06,960 --> 00:00:11,920
Hey everybody what's going on this is Caleb with slopes dotcom in this video we're going to create a

2
00:00:11,920 --> 00:00:18,490
very simple data service that is going to create a static instance of our particular intent for when

3
00:00:18,490 --> 00:00:23,980
we use Siri and this is going to give us access to this instance throughout our entire application no

4
00:00:23,980 --> 00:00:27,330
matter what class we're in because it is a singleton class.

5
00:00:27,340 --> 00:00:32,080
And like I said it's a static instance that will be available throughout the whole lifecycle of the

6
00:00:32,080 --> 00:00:32,940
application.

7
00:00:33,190 --> 00:00:38,530
And basically when the intent comes in to the app delegate from Siri we're going to go ahead and set

8
00:00:38,530 --> 00:00:41,210
that intent in the data service.

9
00:00:41,230 --> 00:00:46,330
So go ahead and pull open your X code project here and let's get started with that now.

10
00:00:46,580 --> 00:00:52,000
You know what we also should kind of clean up our project here so right click on leg day and create

11
00:00:52,000 --> 00:00:57,610
a controller group and make sure that you spell it properly.

12
00:00:57,670 --> 00:00:59,450
Dragon work out VC.

13
00:00:59,740 --> 00:01:01,870
Go ahead and create what else.

14
00:01:01,870 --> 00:01:05,670
We need a services group because we're creating a data service.

15
00:01:05,800 --> 00:01:11,130
We're going to need an extensions group eventually so we'll just create that now.

16
00:01:11,590 --> 00:01:12,710
And yeah.

17
00:01:12,880 --> 00:01:17,380
So let's go ahead and let's actually let's move that that's not right.

18
00:01:18,300 --> 00:01:20,880
It should be outside of the folder.

19
00:01:20,880 --> 00:01:24,050
There we go and extensions should go down below here.

20
00:01:24,400 --> 00:01:24,850
Awesome.

21
00:01:24,850 --> 00:01:28,810
So there's our view controller our services folders what we care about now.

22
00:01:28,810 --> 00:01:33,370
So right click Create a new file and it can just be a swift file.

23
00:01:33,530 --> 00:01:34,160
OK.

24
00:01:34,450 --> 00:01:38,810
Click next and just call it data service.

25
00:01:39,160 --> 00:01:44,740
I guess we could also call it intense service but data service is fine and what we want to do is create

26
00:01:44,740 --> 00:01:52,910
a class called data service like so and now we create a static instance of our class.

27
00:01:52,930 --> 00:02:01,240
So go ahead and type static let instance equals data service and instantiate it just like that.

28
00:02:01,240 --> 00:02:02,690
Now the reason we're using static.

29
00:02:02,710 --> 00:02:09,130
Like I said is because it enables this instance to stay in memory throughout the entire time that this

30
00:02:09,130 --> 00:02:09,810
app is running.

31
00:02:09,810 --> 00:02:12,150
So it'll never get.

32
00:02:12,190 --> 00:02:14,250
It will never become deallocated.

33
00:02:14,260 --> 00:02:16,200
It's going to stay allocated.

34
00:02:16,420 --> 00:02:22,840
So next in our data service what we need to do is basically create a property to hold an eye and start

35
00:02:22,840 --> 00:02:29,200
work out intent but to do that we're going to need to import intense the Syrie get foundation the framework

36
00:02:29,230 --> 00:02:29,770
I mean.

37
00:02:30,180 --> 00:02:38,470
So type import intense and now type var intent or maybe work out in 10 that might be that might be more

38
00:02:38,470 --> 00:02:39,300
specific.

39
00:02:39,490 --> 00:02:43,220
And that's going to be of type I can start work out intent.

40
00:02:43,300 --> 00:02:44,230
I'm actually going to rename it.

41
00:02:44,230 --> 00:02:46,150
Start work out intent.

42
00:02:46,150 --> 00:02:52,530
So that is now accessible to us anywhere in our app and show you that let's go into the app delegate

43
00:02:53,050 --> 00:03:00,490
and we just created an intent here using the data from user activity passed from Siri kit.

44
00:03:00,850 --> 00:03:05,260
And then what we're going to do is we're going to go ahead and call data service which we need to maybe

45
00:03:05,260 --> 00:03:08,230
build to see that there we go.

46
00:03:08,230 --> 00:03:09,460
Data Service.

47
00:03:09,700 --> 00:03:11,000
Instance.

48
00:03:11,200 --> 00:03:16,330
Intent or start work out intent is going to be equal to intent.

49
00:03:16,330 --> 00:03:20,910
So now our start work out intent is set to the intent that comes from Siri.

50
00:03:20,920 --> 00:03:24,760
So we have access to that everywhere in our application now which is really cool.

51
00:03:24,760 --> 00:03:29,950
The only thing is that we're going to need to send a notification to our view controller to notify it

52
00:03:29,950 --> 00:03:31,570
that the data has been updated.

53
00:03:31,690 --> 00:03:35,800
And that's actually what we're going to do in the next video we're going to handle these results that

54
00:03:35,800 --> 00:03:36,890
are coming back.

55
00:03:36,910 --> 00:03:41,950
We're going to be able to pull out some of the data and we're also going to write a handy little extension

56
00:03:42,220 --> 00:03:50,170
for doubles and it's basically going to take a double value and then convert it into a clock times that

57
00:03:50,170 --> 00:03:52,660
we can display it like you would with a timer.

58
00:03:52,660 --> 00:03:58,180
OK so it will return a string that is like a clock time with the minutes a colon and the seconds at

59
00:03:58,180 --> 00:03:58,800
the end.

60
00:03:58,810 --> 00:04:01,810
So let's head over to the next video and let's set that up.

61
00:04:01,810 --> 00:04:03,230
We're going to handle our data.

62
00:04:03,310 --> 00:04:07,370
We're going to send a notification to our view controller to update our labels.

63
00:04:07,480 --> 00:04:13,750
And we're also going to write a little extension that is going to help us convert our double time into

64
00:04:14,110 --> 00:04:14,940
a clock time.

65
00:04:14,950 --> 00:04:17,980
So let's head over there now and let's get started.
