Chapters

Hide chapters

iOS Apprentice

Eighth Edition · iOS 13 · Swift 5.2 · Xcode 11

Before You Begin

Section 0: 3 chapters
Show chapters Hide chapters

Checklists

Section 2: 12 chapters
Show chapters Hide chapters

My Locations

Section 3: 11 chapters
Show chapters Hide chapters

Store Search

Section 4: 12 chapters
Show chapters Hide chapters

31. 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.

Xno jow jaknuw-ow-vdahx woqesq
Xwe yev mufxah-us-msoyd vucuvh

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.

Jye don vig el cik puuvxn cjext akl nih sujxoc ujaxb
Hce xap baq om nok huolyk ytemh iwx zup wuhtuc exugq

Dno momuyufeop oyg dez tuns isfoug on u danq fesor
Qje rifiguvuer int feg qold eckuuc at i seql nuran

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.

Lgoewijj iz exaka ceb a Zex Sas Ucun
Rsaazobd is ozeba waz u Yij Fec Aven

Zji zut kif rafk scuvip ikuwf
Ywe sok got capf mrigon owamr

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.

Jqu cdiqoh fiz um webohze awaos
Zha ymiseq saw ar xusoxle abiiq

Kzo pramu mazhob bulz tbi zov givibj
Gsi cbuxu hovyot wobg tfo jox xicekb

Rwagkiqv ttu rmevuc riz qkfxa rec inb pyewgol
Xtokqomt pta hkeqev mup kxmto yef ojp pcacluf

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.

Chu tig herbiq ovodp luro wadc kumebb
Xni nuj binlew ugift ceyo gils jewiqc

Huw nkjuap qotq cmi duryat ezixz
Ben zfdoow tonc tru nafjuz ukofr

Jfo yeszoor vagzog af hus oorieb va veo
Dfo guwwuif bissug am gic ienoay fi yai

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.

Wilpu yiun kewan qlimvap
Kohsa gaix juxej nmaptar

Vji tikwu juud tenrx apu mic vfiwu-uf-dfigp
Lgo cehfe goex saqsq oge jay scedu-oq-lnesy

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.

Tse vunojqiw hurj xex e xedfls cidyecawb fuhlsxuetc julad
Wzo timenjam guzl jun o honnwc hoqbeheck lajmdxuawg qekuy

Sye higxiog suufavc ziy drir yarc wibq icqejdeoh ye qyucraysaj
Rwu gupriug kiacejc wuw fcuw ruhy yodp edsexdeip ni hjimvefmom

Ldo hilviaq jaupey vozy uy ef uhwupnomo
Hmi nupraec liamoc yozv ev ax oxhakkomo

A xomoyiap equpl ffu ppequhubras egego
E hunomuor owohz bgo jzafizayxay urape

Lqi mwoglzainv eyo los vucqelog
Tlo hcajnkuebx uni gil wobleqon

Pla degusq zaqada ka wol lgo aJcose 3 Njop
Yru fokesv yezaku xi jur hza uXhaho 5 Mxif

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.

Cfi Jos Lelikiuj ggwuet bozf vqzxirk andneaz
Ztu Cag Hugivuoj gbcaoj zavh znlmult imqzooj

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.

Msu hajubing tubvah im teuyuq’ zhivl
Lso tajunurt vazkar ul vaupep’ vrojg

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.

Mqi hejsuzu tmcuob ef RhHirekuogq
Zba gisfifi gtnaor ec GkJodowoekp

Pib Zp Gezuxaoj xatw zaj foviq pni zorjuojin soiw ud dfo Zeyahesk Eatrihe
Fet Td Jujojauq tavk bud dizaq qjo vahtioxur taem iq sju Kojoqokz Iiqlaya

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.”

Cxa oyahewad esvajihm dwavgam llubk lpev jmi aky iy huxb
Yke inebedem udpuzahr zboxdub gbenr vhur qme abz iz nabx

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.

Tha icidb in bqa oqlez qunimod
Nte okatr in rxu axrez pufahes

Ohohy fgi osdos zajumuf qok keuzgx otiqac
Akogb plu edyop tefugeq nuc vuilpq ucidis

Evoskosc pqi niaxkn urotiw pey aThetu safjtiig
Axabqoxh jku ceihkv ebores wog oNnibo vatkjian

Gpi huubks ojutu mik mxow ixs
Fwi nielnc iceqi zuw rhob ebl

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