Sorry for the wait! A lot of the people who liked part 1 & 2 wanted me to create a part 3 to this series to include search implementation and updating journals so in this article I’ll show you just that.

In case you missed the previous parts here’s part 1 and part 2.

As always you can check out the finished app on my GitHub.

Let’s get started.

Updating Entries

We need a way to select a entry row and then segue to another view in order to edit that entry.

I decided to use the selectRowAt to identify the indexPath.row of the selected entry.

At the top of the DisplayTableViewController let’s add a variable to represent the integer of the indexPath.row that was selected.

I called mine selectedIndex .

The great thing about UITableViewController , is that Apple provides a ton of prewritten methods we can add.

In our case, we will be adding didSelectRowAt .

In side this method let’s give selectedIndex a value, which is indexPath.row .

Basically meaning, the row number that the user tapped.

Keep in mind, like arrays, rows start from 0 not 1.

For example, you selected row 2, the indexPath.row will output 1.

The last line, simply deselects the row after tapping a cell.

Segue

We need to segue to another view where we can allow a user to edit the entry.

First we need to create a UIViewController in storyboard, or if you prefer you can do it programatically.

I won’t be really going over the UI, I was lazy and I copied the new entry UI and just changed the labels to fit the update view look.

Check out the completed project if your curious.

After you create the UIViewController , you’ll obviously need to create a cocoa file along with that. So make sure you add it to it’s class.

Now that we have a controller, let’s create a segue from the main table view to the update controller.

Control + Drag from the table view controller to the update controller.

Select Present Modally .

Now select the modal, and open the attributes inspector.

Give the modal an identifier.

Now we can add this line to our didSelectRow .

Now you should be able to tap and segue.

Passing data between controllers

We need to be able to pass our item (our entry) to our update view controller to be able to edit.

To do this, open your update view controller file.

Mine is called UpdateItemViewController.swift

At the top of the file under class let’s add a variable of type Item , which is our core data entity.

To pass the data to our item variable in UpdateItemViewController , we will utilize prepareForSegue .

Go back in the main table view controller add this func.

Remember we named our segue “UpdateVC”, we will be using that to identify that that specific segue has been called.

Let’s set our item variable now.

You see we are using our selectedIndex we set back in didSelect to grab the item from our items array.

Inside UpdateItemViewController , we can print our item to make sure we are actually passing it.

Let’s now show the entry in the UITextView.

Create a func called configureEntryData that takes a parameter of Item .

Inside we will set the text.

Make sure to call configureEntryData() in viewDidLoad() .

Now that we have the text showing, let’s do an update action.

It’s simple.

As you see in the button’s action we first do a guard, then we save and dismiss the modal.

Search

A lot of you have been asking me for search especially so here it finally is.

This is a very barebones simple implementation of search but it works quite well.

First let’s open up DisplayTableViewController .

Let’s create a func called createSearchBar .

Inside this function we will create UISearchBar and add it to our navigation bar.

Make sure to add UISearchBarDelegate .

So we need to have another array where we show our filtered data.

Create a var , filteredData .

We need to make our filteredData array equal to the same items array.

In our previous fetchData() method, make filteredData equal to items .

To update the table with the searched text we need to implement textDidChange function.

First lets see if the search bar text is empty, if so then no changes.

Now let’s filter.

Basically what were doing here is filtering through the items array which with the .name contains any of the text that the user types.

After the else block, let’s update our table.

All you need to do now is to replace the cellForRow, numberOfRows, and editActionsForRowAt to the filteredData instead of items .

Wrapping up

I hope this article helps, I know many of the people who liked the part 1 and 2 were asking me for a long time to implement updating entries and search.

Please as always leave any questions, comments or suggestions in the comments.

Thanks for checking out the article!