Chapters

Hide chapters

SwiftUI Apprentice

Second Edition · iOS 16 · Swift 5.7 · Xcode 14.2

Section I: Your First App: HIITFit

Section 1: 12 chapters
Show chapters Hide chapters

Section II: Your Second App: Cards

Section 2: 9 chapters
Show chapters Hide chapters

12. Apple App Development Ecosystem
Written by Audrey Tam

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

Here’s one more overview chapter before you move on to build the other two apps in this book.

While building HIITFit, you learned a lot about Xcode, Swift and SwiftUI at a detailed level. In the previous chapter, you got a kind of “balcony view” of how the various property wrappers help you manage the state of your app’s data. This chapter provides a bird’s eye view of the whole Apple app development ecosystem, demystifying many of the terms you might hear when iOS developers get together for a chat. You’ll start to build your own mental model of how all the parts fit together, creating your own framework for all the new things that Apple adds every year.

A Brief History of SwiftUI

You’ve been using SwiftUI to build HIITFit, but this is only the most recent app development paradigm from Apple.

Apple announced SwiftUI at its World Wide Developers Conference in June 2019. SwiftUI builds on the Swift programming language, which Apple announced in June 2014. SwiftUI is a Domain Specific Language (DSL), written in Swift using these new Swift features:

  • Property wrappers, like @State to monitor the state of properties.
  • Result builders, like @ViewBuilder to create view hierarchies.
  • Opaque result types, like some View to avoid explicitly writing out the view hierarchy.

Swift creates faster, safer apps than Objective-C and is more protocol-oriented than object-oriented. Chapter 15, “Structures, Classes & Protocols”, explains the difference between class inheritance and protocols.

By January 2018, the Redmonk Programming Language Rankings ranked Swift and Objective-C in a tie at number 10.

Objective-C entered Apple history when Apple bought NeXT in 1997, which also brought Steve Jobs back to Apple. Jobs had resigned from Apple in 1985 after losing a boardroom battle with CEO John Sculley over the future of the Macintosh computer. Jobs, with five other former Apple executives, then founded NeXT Computers.

A brief history of SwiftUI
A brief history of SwiftUI

The NeXTSTEP operating system, written in Objective-C, formed the basis of Mac OS X, released in 2001. Apple provided the Cocoa API for developers to create apps for OS X. Cocoa consists of three frameworks reflecting the Model-View-Controller principles: Core Data, AppKit and Foundation. The “NS” prefix in AppKit and Foundation acknowledges their NeXTSTEP heritage.

Apple announced the iPhone in 2007 and the iPhone SDK (Software Development Kit) in 2008. This included Cocoa Touch, with UIKit replacing AppKit. Now called the iOS SDK, it helps you create apps that appear and behave the way users expect.

Fun Facts

  • The first World Wide Web server was a NeXT Computer, and id Software developed the video games Doom and Quake on machines running the NeXT operating system NeXTSTEP. In 1996, NeXT Software, Inc. released WebObjects, a framework for Web application development. Apple used WebObjects to build and run the Apple Store, MobileMe services and the iTunes Store.
  • Cocoa != Java for kids: Before Jobs returned to Apple, the Apple Advanced Technology Group created KidSim, an app to teach kids to program. KidSim programs were embedded in web pages to run, so they renamed and trademarked the app as Cocoa — “Java for kids”. The Cocoa program was one of the many axed in 1997, and Apple reused the name for the OS X API to avoid the delay of registering a new trademark.
  • While developing the iPhone, Steve Jobs didn’t want non-Apple developers to build native iPhone apps. They were supposed to be content making web applications for Safari. This stance changed in response to a backlash from developers, and the iPhone SDK was released on March 6, 2008.

SwiftUI vs. UIKit

Although you’ve used only SwiftUI to create HIITFit, UIKit has a lot of resources that can help you add features to your app or fine-tune how it looks and functions.

Most Popular Episode

“SwiftUI vs. UIKit” is the most popular free episode at kodeco.com. Presented by our founder Ray Wenderlich, it’s worth watching, but here’s a TL;DW summary.

SwiftUI or UIKit?
JbursOU ok UERul?

Integrating New & Old

Apple always provides support for developers to transition to new things. The Carbon API enabled developers to port “classic” Mac OS apps to OS X. Bridging headers enable developers to use Objective-C code in Swift apps and vice versa.

Integrating a UIKit view
Uwbelyupejk u UOGij rieh

SFSafariViewController in TheMet app
VGDuwazaDoupZiwztaclis uv ZboPog acs

Apple Developer

Despite Steve Jobs’ initial intentions, Apple would like everyone to be an Apple developer. Your needs and interests might be shared by a few other people or by a lot of other people. But maybe not by professional iOS developers. If you create an app you need or want, it becomes available to those other people too. Even better if your app uses some technology that only works on the newest Apple gadgets, so they have to upgrade to use your app. ;]

WWDC

Every June, Apple holds the 5-day World Wide Developers Conference — WWDC, often pronounced dub-dub-dee-cee or shortened to dub-dub. The keynote on day 1 shows off all the features planned for the new versions of iOS, macOS and all the other OSes. These launch later in the year, around September or October.

Apple Developer app
Aqhxo Lutevohib ehb

Platforms

Using SwiftUI to build new iOS apps makes it easier to create similar apps on Apple’s other platforms: macOS, watchOS and tvOS. It’s not that your iOS app will “just work” on another platform. It probably won’t.

#if targetEnvironment(macCatalyst)
...
#endif

Frameworks

The SDK has a lot of frameworks, and Apple adds new ones every year. The ones every app needs are modernized versions of the original Cocoa:

AVKit for AVPlayer in VideoPlayer
OTYiv gic ICGjapim av NuxeeLvifud

Charts in HistoryView
Gyeqld aq JibmetyQaac

PhotosUI with PhotosPicker
NqeqayEO pogs WbavofFuwzak

SwiftUI Charts widget
SnihbEA Ljuzqx wisboy

Newest MapKit tutorials
Purukx DirLok pufiguimr

Apple Augmented Reality by Tutorials
Unjyi Uadrodmes Foawusv hr Nexeqeeqb

Apple Developer Technologies filtered for 'data'
Otcgu Wesifizoj Fesswejahaik bawbomih cok 'sepo'

Apple Developer app: Videos classified by topic
Obpqe Foyibaxip osx: Foneef gkihxemaon zt tehaj

Capabilities

Many of the frameworks are for adding special features to your apps. Apple calls these capabilities.

Capabilities
Jenogavoseaq

Capabilities Available to Developers
Buwemanexuoh Ukauhucto ja Motakihiny

Developer Programs

So what are the three types of Developer?

App Distribution

The actual procedure for getting your app into the App Store changes a little bit every year. Apple’s documentation can be confusing.

Housekeeping & Trouble-Shooting

Hopefully, you haven’t run into any issues while creating HIITFit. Xcode’s error and warning messages are often helpful, but sometimes they’re just wrong. At first, you won’t be sure if it’s something you need to fix but, as you gain more experience, you’ll get a feeling for when Xcode is wrong or confused. It does happen. When it happens to an iOS developer, one of the first things they do is Clean Build Folder. Read on to find out what this involves.

DerivedData/Build

Xcode maintains a lot of files in ~/Library/Developer/Xcode. Of particular interest is DerivedData, where Xcode creates a folder for every project you’ve ever created or opened. This is where Xcode stores intermediate build results, indexes and logs.

Show Build Folder in Finder.
Vkij Yuedx Bakbup of Dertok.

Scroll left in Finder.
Vhqakh bodx ek Winzup.

Open Build folder.
Uhov Xaovb zufpak.

Locate x86_64 or arm64 folder.
Soqupe n10_78 uw atl79 woxhah.

Sort x86_64 or arm64 by Date Modified.
Fijw v56_50 ac icn60 hx Hola Xosiceoc.

Build after code change
Giark iyqew leko ktekko

Empty Build folder
Uvpnt Deuhr gekzeg

DerivedData

The rest of your app’s folder in DerivedData stores data and indexes that Xcode uses for search, Open Quickly and refactoring. Again, sometimes these get mixed up, causing strange Xcode behavior. There’s no menu command to delete these files. You just have to delete the whole derived data folder and let Xcode re-create it.

Go to derived data folder.
Qa pe wapiqiy biho hofrif.

New derived data folder
Jul koloxoc baza vejwiw

When Xcode Behaves Strangely

Xcode is a hugely complex app, and sometimes it needs a nudge or something stronger to “clear its head”.

Reclaiming Disk Space

Weird Xcode behavior isn’t the only reason to delete derived data folders. Long after you’ve finished working on a project — or even deleted it — its derived data folder is still there, taking up disk space. Many developers routinely delete the entire DerivedData folder every month or so, reclaiming gigabytes of space. If you’re running low on disk space, it’s certainly the first place you should look.

rm -rf ~/Library/Developer/Xcode/DerivedData/*
macOS Developer storage management
nahES Hemozezah dlugoxo toyifeveqf

Seeking Help From the Community

SwiftUI’s error messages can be mysterious. If you get an error message and can’t figure out what it wants you to do, select the whole message, then select Search With Google from the right-click menu.

iOS Dev Happy Hour
oEL Vop Cuxpw Fiex

Key Points

  • SwiftUI is a Domain Specific Language built on Swift, a faster and safer programming language than Objective-C.
  • “SwiftUI vs. UIKit” is the most popular free episode at Kodeco and answers the big question: Which should you learn?
  • You can use UIKit views and view controllers in your SwiftUI apps.
  • Apple provides a lot of resources to help you become a developer and stay up to date: Documentation and human interface guidelines are available on the website and in Xcode. Use the Apple Developer app to watch WWDC videos.
  • The iOS Software Development Kit has a lot of frameworks, many for adding special features (capabilities) to your apps.
  • Members of the Apple Developer Program can add all the capabilities and also get early access to beta operating systems and developer tools. And, only members can participate fully in WWDC.
  • Xcode stores intermediate build results, indexes and logs in your project’s derived data folder. Sometimes you need to Clean Build Folder or delete the entire derived data folder. To reclaim disk space, periodically delete the whole DerivedData directory.
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.
© 2024 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