1
00:00:06,030 --> 00:00:12,320
What's up guys I'm Jacob with Devon slopes dot com and we pretty much finished our app it's completely

2
00:00:12,330 --> 00:00:19,040
running but I want to show you one more thing with relm like how you can pull a specific object out

3
00:00:20,060 --> 00:00:25,400
just so you kind of have a good head start for the exercise because right now we're just returning a

4
00:00:25,430 --> 00:00:31,150
whole results array for the most part a sorted one.

5
00:00:31,160 --> 00:00:36,180
But we're still not showing you how to grab one object so I'm willing to do that real quick.

6
00:00:36,200 --> 00:00:45,540
And if we go into our run model we have our one static function get all runs.

7
00:00:45,650 --> 00:00:50,190
But we also want maybe to get one run right.

8
00:00:50,360 --> 00:00:55,430
So let's make another static function and let's call it gets run

9
00:00:58,160 --> 00:01:10,270
and here we'll say for or let's say get run and we can just say by id and then we'll pass in an ID which

10
00:01:10,270 --> 00:01:24,420
is a string and this will return one optional run object instead of an entire results collection.

11
00:01:24,460 --> 00:01:26,320
So if we do that.

12
00:01:26,430 --> 00:01:33,340
The really cool thing with realm is you can so since it's by ID we're going to just pull it out of the

13
00:01:33,340 --> 00:01:38,070
realm objects by primary key.

14
00:01:38,200 --> 00:01:41,770
So we'll do our DO WHILE.

15
00:01:41,770 --> 00:01:45,280
So we can do our try or our DO catch I'm sorry.

16
00:01:45,670 --> 00:01:47,650
So let's see.

17
00:01:47,650 --> 00:01:51,350
And here we'll just return nil.

18
00:01:51,560 --> 00:01:57,260
And now we can do our relm equal try Rome.

19
00:01:57,470 --> 00:02:05,930
And we want to call our configuration that we created a couple lessons ago and this is our relm config

20
00:02:05,930 --> 00:02:06,740
file.

21
00:02:06,950 --> 00:02:08,540
Run config.

22
00:02:08,800 --> 00:02:10,580
OK so once we have our type

23
00:02:13,420 --> 00:02:17,630
or once we have our Rome Poyan from our new realm config.

24
00:02:17,920 --> 00:02:28,840
All it to do is make a variable called Run and say round object a singular object of type run dot self

25
00:02:29,500 --> 00:02:35,460
and we want it for loops for primary key.

26
00:02:35,750 --> 00:02:36,090
Right.

27
00:02:36,130 --> 00:02:43,830
And all we're going to do is pass the ID from our function from the parameter and our function pass

28
00:02:43,830 --> 00:02:51,040
that in and all we have to do now is return runs so we can actually just do this.

29
00:02:51,210 --> 00:02:52,140
Less lines of code.

30
00:02:52,140 --> 00:02:53,430
We can just return this

31
00:02:57,480 --> 00:02:59,140
and delete that line.

32
00:02:59,550 --> 00:03:06,780
And so we pull our run collection out of our realm object and only grab our primary key and there can

33
00:03:06,780 --> 00:03:11,140
only be one object per primary key.

34
00:03:11,640 --> 00:03:13,950
And now to verify that this works.

35
00:03:13,950 --> 00:03:22,770
If we go over to our beginner run VC and let's see we mapped Let's see

36
00:03:28,420 --> 00:03:35,320
OK our locations here instead of just using our last run and obviously this is fine because we already

37
00:03:35,350 --> 00:03:44,120
got it as our first parameter but let's pretend we're not sure if that is the right object.

38
00:03:45,580 --> 00:03:49,480
Like I said you wouldn't really do it here I just want to show you how you would use it.

39
00:03:49,660 --> 00:03:51,090
So we could do.

40
00:03:51,610 --> 00:03:55,390
Let's see let locations actually

41
00:03:58,010 --> 00:04:10,140
guard let locations equal run dot get run by id and we will pass in our last run.

42
00:04:12,040 --> 00:04:24,260
Dot ID and then we'll just call our locations off of that and then Alce just return a empty poly M.K.

43
00:04:24,270 --> 00:04:27,470
polyline.

44
00:04:27,930 --> 00:04:36,480
If it is nil and if it's not nil we'll have locations down here now and we'll just replace last run

45
00:04:36,480 --> 00:04:45,600
locations with locations and then also down here last run locations we can just change to locations

46
00:04:48,210 --> 00:04:54,060
obviously what we're doing here is a little redundant because we already grab the object we need but

47
00:04:54,060 --> 00:04:58,270
I'm showing you how to grab one object by an ID.

48
00:04:58,560 --> 00:04:59,880
So let's go ahead and run it.

49
00:04:59,910 --> 00:05:07,170
And as long as our poly line shows up on our last run which I believe was a freeway line we should be

50
00:05:07,170 --> 00:05:08,250
good to go.

51
00:05:13,870 --> 00:05:16,260
And there's our polyline the freeway line.

52
00:05:16,330 --> 00:05:22,820
So we're grabbing the same object just by ID instead of doing like a dot first which is pretty cool.

53
00:05:24,590 --> 00:05:25,010
All right.

54
00:05:25,010 --> 00:05:27,370
So that's all I wanted to show you in this lesson.

55
00:05:27,380 --> 00:05:31,940
And you can obviously do all sorts of cool stuff.

56
00:05:32,060 --> 00:05:39,580
Just like in our get all runs we sorted by date you can sort and filter all sorts of things so that

57
00:05:39,590 --> 00:05:42,820
filter is also something you can do.

58
00:05:42,890 --> 00:05:45,390
So yeah.

59
00:05:46,520 --> 00:05:53,480
The last lesson in this course is going to be an exercise and it's going to test your knowledge and

60
00:05:53,480 --> 00:05:59,360
see if you can make your own relm functions to return the data and different orders.

61
00:05:59,360 --> 00:06:03,310
So I will see you guys in the next lesson.

62
00:06:04,290 --> 00:06:09,800
Yeah but this course is done we made a really cool Nike clone so that's sweet and I'll see you guys

63
00:06:09,800 --> 00:06:11,460
later.
