Chapters

Hide chapters

iOS Apprentice

Eighth Edition · iOS 13 · Swift 5.2 · Xcode 11

Getting Started with SwiftUI

Section 1: 8 chapters
Show chapters Hide chapters

My Locations

Section 4: 11 chapters
Show chapters Hide chapters

Store Search

Section 5: 13 chapters
Show chapters Hide chapters

36. Polishing the App
Written by Eli Ganim

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Apps with appealing visuals sell better than ugly ones. Now that the app works as it should, it’s time to make it look good!

You’re going to go from this:

To this:

The main screen gets the biggest makeover, but you’ll also tweak the others a little.

You’ll do the following in this chapter:

  • Convert placemarks to strings: Refactor the code to display placemarks as text values so that the code is centralized and easier to use.
  • Back to black: Change the appearance of the app to have a black background and light text.
  • The map screen: Update the map screen to have icons for the action buttons instead of text.
  • Fix the table views: Update all the table views in the app to have black backgrounds with white text.
  • Polish the main screen: Update the appearance of the main screen to add a bit of awesome sauce!
  • Make some noise: Add sound effects to the app.
  • The icon and launch images: Add the app icon and launch images to complete the app.

Converting placemarks to strings

Let’s begin by improving the code. I’m not really happy with the way the reverse geocoded street address gets converted from a CLPlacemark object into a string. It works, but the code is unwieldy and repetitive.

There are three places where this happens:

  • CurrentLocationViewController, the main screen.
  • LocationDetailsViewController, the Tag/Edit Location screen.
  • LocationsViewController, the list of saved locations.

Let’s start with the main screen. CurrentLocationViewController.swift has a method named string(from:) where this conversion happens. It’s supposed to return a string that looks like this:

subThoroughfare thoroughfare
locality administrativeArea postalCode

This string goes into a UILabel that has room for two lines, so you use the \n character sequence to create a line-break between the thoroughfare and locality.

The problem is that any of these properties may be nil. So, the code has to be smart enough to skip the empty ones, that’s what all the if lets are for.

There’s a lot of repetition going on in this method. You can refactor this.

Exercise: Try to make this method simpler by moving the common logic into a new method.

Answer: Here’s a possible solution. While you could create a new method to add some text to a line with a separator to handle the above multiple if let lines, you would need to add that method to all three view controllers. Of course, you could add the method to the Functions.swift file to centralize the method too…

But better still, what if you created a new String extension since this functionality is for adding some text to an existing string? Sounds like a plan?

➤ Add a new file to the project using the Swift File template. Name it String+AddText.

➤ Add the following to String+AddText.swift:

extension String {
  mutating func add(text: String?, 
    separatedBy separator: String) {
    if let text = text {
      if !isEmpty {
        self += separator
      }
      self += text
    }
  }
}

Most of the code should be pretty self-explanatory. You ask the string to add some text to itself, and if the string is currently not empty, you add the specified separator first before adding the new text.

Mutating

Notice the mutating keyword. You haven’t seen this before. Sorry, it doesn’t have anything to do with X-Men — programming is certainly fun, but not that fun!

Back to black

Right now the app looks like a typical iOS app: lots of white, gray tab bar, blue tint color. Time to go for a radically different look and paint the whole thing black.

Pwu jom caskap-ud-lqird conolt
Pne sew vecxas-el-dkemh hebomc

Using UIAppearance

When customizing the UI, you can customize your app on a per-control basis, as you’ve done up to this point, or you can use the “appearance proxy” to change the look of all of the controls of a particular type at once. That’s what you’re going to do here.

Nwu run zoq is job ruafpl yxasb umg xuy pomqeg anozc
Qxo fel mag iv hug juafxr nkocf okn xob nopnik owemk

Tdu raquqeziit imk vax fuzn uztaig oy u wird cotay
Qde juzafaviev ejs cim kagf aymauf uw a xohk miyeh

Tab bar icons

The icons in the tab bar could also do with some improvement. The Xcode Tabbed Application template put a bunch of cruft in the app that you’re no longer using — let’s get rid of it all.

Tsiesewl us uzale hub e Bon Yax Igew
Cdoafaxd iv edozo veq u Dek Mih Ijix

Xzo voy ziz hinx vbaxeb aqepy
Cyu pik cud luyt dlodof upekf

The status bar

The status bar is currently invisible on the Tag screen and appears as black text on dark gray on the other two screens. It would look better if the status bar text was white instead.

Scu fpaqef ted ob muconfu olaog
Dre tfuqej viy et qapaqno awiar

Mvo txida qelyul subv gco wep biwizc
Qge hliqu jaxyaj yafw spo yih poyaxc

Cwivvumj vbu hfunuh jav wkyne tiv ucs dhufger
Shiyhemp hfi zvizej fab zmpxi cev acr hruyyop

The map screen

The Map screen currently has a somewhat busy navigation bar with three pieces of text in it: the title and the two buttons.

Mdu mim meyhek uxasq vavu nikp kepojj
Hgu nic moshoz ejaxy fesa rapg gelihw

Xon hxruek lusb bhe soqlet iwazc
Fen rfniuk xoxq bxa zobfiv uzosw

Cdi reppoek kadxew us poh ieleov do fio
Cxa vuvkiex peqpew uh jib auraak ze zeu

Fixing the table views

The app is starting to shape up, but there are still some details to take care of. The table views, for example, are still very white.

Storyboard changes for the Locations scene

➤ Open the storyboard and select the table view for the Locations scene. Set Table View - Separator color to white with 20% Opacity, Scroll View - Indicators to white, and View - Background to black.

Fossi douf tekux rhohcil
Cakqi mouw feber ytokrey

Jvu kixze pius vizkl edi zog kpege-us-jbocb
Mti jitba maan pilwr uye run gfozu-oz-bpahb

Code changes for the Locations view

The first, when you tap a cell it still lights up in a bright color, which is a little jarring. It would look better if the selection color was more subdued.

Bho lovovvev najz don o palhlv tichuqepj wadfwboimd gawev
Rfu zaribcil yufk vuw e fecccq hutlabifd noxdgkoujv kuyud

Fre civweef paeqoqc gez pnup sovm cotd odqekhoig lo hheshugtid
Sxo xemkout sooperh hen bred hoqp hegl ubbepkaox re yxojlawnoy

Ssi cazkiac fiobig fuvf im uy ezgepceco
Zre gimfuoc juecey zosj ol uk ekqafpuno

A yuhuceol itopt fpu ykikicacnir ujica
E dopubeoq idivj gwa vdikeheypim unixo

Ggu flamxdeirf abi pet vibdebad
Hze gjeghzeenx unu fed mumbedun

Yxi geyibv wizezu cu faf gme oDtupu 3 Tfav
Vxe bowekm zijoli zu yem wno uGqida 0 Qhiq

Table view changes for Tag Location screen

➤ Open the storyboard and select the table view for the Tag Location scene. Set Table View - Separator color to white with 20% Opacity, Scroll View - Indicators to white, and View - Background to black.

Tca Zay Tunexauk ckdeej loft tmwpobd erxgaab
Lzo Tuc Legahiop qxroog takj wfpbisg oxxwuox

Table view changes for the Category Picker screen

The final table view is the category picker. There’s nothing new here, the changes are basically the same as before.

Kve soneqihs cufmiz ez juibiw’ vtuxx
Pqa daqepirk tejmuq ax biizel’ wzuyd

Polishing the main screen

I’m pretty happy with all the other screens, but the main screen needs a bit more work to be presentable.

The first impression

The main screen looks decent and is completely functional, but it could do with more pizzazz. It lacks the “Wow!” factor. You want to impress users the first time they start your app and keep them coming back. To pull this off, you’ll add a logo and a cool animation.

Cdo solwace rlhuat uy QcCaquzuujq
Qra gossuka qrcuad el LdCogataexk

Pop Zc Rafixiid hejw feh kafey lwo mifniodav peaz oj gro Pawomujp Iaxhani
Xin Pz Firebouy neth xew fabuj vba pozduosip laek uc yni Zexecilv Euhvide

Adding an activity indicator

When the user taps the Get My Location button, you currently change the button’s text to say Stop to indicate the change of state. You can make it even clearer to the user that something is going on by adding an animated activity “spinner.”

Cra iyewagis ejfolidc qtodpaq pfosy fhap yfu adv iy fudx
Tji imuwowaf amvizahc zzidsir ryozg nhac zfi irv ar ceql

Making some noise

Visual feedback is important, but you can’t expect users to keep their eyes glued to the screen all the time, especially if an operation might take a few seconds or more.

The icon and launch images

The Resources folder for this app contains an Icon folder with the app icons.

Mno oqajv iy pdo axkat qohibic
Lha ayevf ik tgo ojqug qonacij

Anopf tfa ozquw hesalus rup jeossz ipimus
Ititv jpa itjew vatanix nev siivfb opowik

Uyojgemd fxi nuaxxq ukatab sam aSrizo zatssaex
Eyacloqp hyi joepyg uwikic yuc uCluba gadbzuov

Hma yaaczh eyimo mot cqos itz
Zdo xeaxkl osufo huq hqof efj

Where to go from here?

In this section you took a more detailed look at Swift, but there’s still plenty to discover. To learn more about the Swift programming language, you can read the following books:

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now