What's up guys I'm Jacob with Devon slopes dot com and we pretty much finished our app it's completely
running but I want to show you one more thing with relm like how you can pull a specific object out
just so you kind of have a good head start for the exercise because right now we're just returning a
whole results array for the most part a sorted one.
But we're still not showing you how to grab one object so I'm willing to do that real quick.
And if we go into our run model we have our one static function get all runs.
But we also want maybe to get one run right.
So let's make another static function and let's call it gets run
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
is a string and this will return one optional run object instead of an entire results collection.
So if we do that.
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
realm objects by primary key.
So we'll do our DO WHILE.
So we can do our try or our DO catch I'm sorry.
So let's see.
And here we'll just return nil.
And now we can do our relm equal try Rome.
And we want to call our configuration that we created a couple lessons ago and this is our relm config
file.
Run config.
OK so once we have our type
or once we have our Rome Poyan from our new realm config.
All it to do is make a variable called Run and say round object a singular object of type run dot self
and we want it for loops for primary key.
Right.
And all we're going to do is pass the ID from our function from the parameter and our function pass
that in and all we have to do now is return runs so we can actually just do this.
Less lines of code.
We can just return this
and delete that line.
And so we pull our run collection out of our realm object and only grab our primary key and there can
only be one object per primary key.
And now to verify that this works.
If we go over to our beginner run VC and let's see we mapped Let's see
OK our locations here instead of just using our last run and obviously this is fine because we already
got it as our first parameter but let's pretend we're not sure if that is the right object.
Like I said you wouldn't really do it here I just want to show you how you would use it.
So we could do.
Let's see let locations actually
guard let locations equal run dot get run by id and we will pass in our last run.
Dot ID and then we'll just call our locations off of that and then Alce just return a empty poly M.K.
polyline.
If it is nil and if it's not nil we'll have locations down here now and we'll just replace last run
locations with locations and then also down here last run locations we can just change to locations
obviously what we're doing here is a little redundant because we already grab the object we need but
I'm showing you how to grab one object by an ID.
So let's go ahead and run it.
And as long as our poly line shows up on our last run which I believe was a freeway line we should be
good to go.
And there's our polyline the freeway line.
So we're grabbing the same object just by ID instead of doing like a dot first which is pretty cool.
All right.
So that's all I wanted to show you in this lesson.
And you can obviously do all sorts of cool stuff.
Just like in our get all runs we sorted by date you can sort and filter all sorts of things so that
filter is also something you can do.
So yeah.
The last lesson in this course is going to be an exercise and it's going to test your knowledge and
see if you can make your own relm functions to return the data and different orders.
So I will see you guys in the next lesson.
Yeah but this course is done we made a really cool Nike clone so that's sweet and I'll see you guys
later.