1

Xcode Workflow Preview

8:20FreeDone
2

Start Designing in Xcode

3:46FreeDone
3

Navigation Controllers and Prototyping

3:04FreeDone
4

Designing The Home Screen

3:14FreeDone
5

Creating Custom Classes

4:52FreeDone
6

Customizing The TableView

4:37FreeDone
7

Adding Logic To The Styling

3:29FreeDone
8

Custom Fonts

6:58FreeDone
9

Saving Variables and Triggering Alerts

6:40FreeDone
10

Integrating Pods In Your Xcode Project

2:24FreeDone
11

Recognizing Gestures on UI Elements

3:26FreeDone
12

Retrieving Data From an API

6:56FreeDone
13

Implementing a Custom Loading Animation

4:34FreeDone
14

Saving and Persisting User Data

3:11FreeDone
15

Encoding and Saving Complex Data

3:35FreeDone
16

Make UI Updates More Granular

2:22FreeDone
17

Refactoring Saved Locations

6:11FreeDone
18

Fine-Tuning TableView Interactions

2:29FreeDone

Comparing Custom Classes

3:42FreeDone
20

Make a Custom Popup UI

4:26FreeDone
21

Adding Actions to TableView Cells

3:27FreeDone

Comparing Custom Classes

Published by Chris Slowik

Episode Notes

Extra tips from the author

Two Approaches to Comparison

By default, our new SavedLocation won't work with the contains function we're using to check if a location is in the savedLocations array.

if !savedLocations.contains(tempLocation!) {
    //...
}

A subclass of NSObject must override isEqual to describe how the objects should be compared. Alternatively, we could add a custom predicate to the contains function to describe how it should compare each array element.

if !savedLocations.contains {$0.name == tempLoaction?.name} {
    //...
}

Essentially what this does is check each element in savedLocations, and compares the name property to the name property of tempLocation. If they're equal, contains returns true.

The only problem with this is that we'd have to use a predicate like this in every instance where we want to compare locations. It's much better to override isEqual in the object class. That looks like this:

override func isEqual(_ object: Any?) -> Bool {
    guard let otherLocation = object as? SavedLocation else { return false }
    return self.name == otherLocation.name
}

First, we check to make sure the object being compared is a savedLocation. If not, we return false because they are obviously not equal. Then, we simply compare the two name properties. If they're equal, the comparison returns true.

Episode Topics: