Apple Development
iOS Performance
iOS Performance tips you probably didn’t know (from an ex-Apple engineer)
I have spent the past 6 years at Apple working on macOS and iOS system frameworks and first party apps. Working on software that ships to hundreds of millions of devices means that extra care needs to be taken to make sure apps launch quickly, are responsive to user interaction and keep their memory usage low.
I have noticed that there was a pattern of low-hanging fruits, where you could make 80% of the performance gains in 20% of the time.
Here’s a checklist of performance tips that would hopefully give you the biggest bang for your buck
Follow-up by Paul Hudson (@twostraws) on UIKit clearing RAM for hidden labels
Swift Library: Time
Time
is a Swift package that makes dealing with calendar values a natural and straight-forward process.
Working with calendars can be extremely complicated and error-prone.
Time
solves these problems by clarifying concepts and restricting improper usage through type-safe APIs.
The Basics
Here’s the TL;DR of the documentation:
-
If you want to know what time it is, you need a
Clock
. You can get the device’s clock by usingClock.system
. -
A
Clock
can tell you the current time via some functions. For example,.today()
will give you the current calendar day..thisMinute()
will give you the current time, accurate down to the minute level. -
Each of these returned values has methods to retrieve more- and less- precise values. For example,
today.hours()
will give you a sequence of all the “Hour” values in the day. -
These values also are how you format them into human-readable strings (via the
.format(...)
method)
SwuftUI course by Stanford University
Using PHPickerViewController Images in a Memory-Efficient Way
SwiftFormat
A command-line tool and Xcode Extension for formatting Swift code
More info on GitHub/nicklockwood/SwiftFormat
There is a command line tool for formatting swift files through the terminal. Simply install it via Homebrew:
brew install swiftformat
Xcode Source Editor Extension
You can also easily add it to Xcode as an extension. First, install it via Homebrew:
brew install --cask swiftformat-for-xcode
After installing it, open it and follow the instructions to add the tool to Xcode. In Xcode, you will find the tool under the ‘Editor’ section in the menu bar at the very bottom with the three commands:
- Format Selection
- Format File
- Lint File
As a bonus tip, you can add a key combo in the Xcode settings under ‘Key Bindings’, e.g. ⌥⌘L
.