If you have been writing iOS apps and publishing them to the App Store, you have an implicit goal to make them better, faster, and more fluidnot to mention loved by your users. And if you are continuously looking for ways to achieve that goal, then this book is just for you.
You should already have working knowledge of Objective-C and iOS. This book is not about jump-starting with Objective-C or iOS, though the fundamentals will be revisited for completeness when necessary.
Why I Wrote This Book
iPhone OS 1 and iPhone 1 were launched in June 2007. During their early releases, developers were busy flushing out code and releasing apps for a wider audience. As the hardware, OS, networks, and overall ecosystem advanced over timeand as new user interface (UI) and engineering design patterns emergedapps matured in functionality, stability, and performance.
More often than not, performance is an afterthought. And I can, to some degree, agree with that approach. After all, it is important to first get the functionality right, rather than worrying about performance. Thinking about optimizing early in the development lifecycle is more commonly referred to as premature optimization. But when poor performance hits, it hits hard.
The primary goal of this book is to show you how to write optimal code from an engineering perspective.
This book is not about theoretical computer science, data structures, and algorithms for faster execution of a task. You can find tons of literature on those topics. It covers best practices for implementing an app in such a manner that even in non-ideal conditions (low storage space, poor network, low battery, etc.), users still can use your app effectively and love using it. Generally, it will not be possible to optimize across all the parameters, but youll be able to achieve the best trade-off considering the available options.
Navigating This Book
This book is organized in five parts. Each part is comprised of one or more chapters that detail the theme of the particular part. Each chapter begins with a brief abstract outlining the topics that will be covered.
discusses the aspects that we want to optimize and outlines the parameters we want to measure as part of tracking app performance.
addresses memory management. It describes the memory management model and object reference types. It also discusses best practices for design patterns that impact memory consumption, namely singleton and dependency injection.
provides an overview of concurrent programming. It describes the various options available and gives a comparative analysis.
provides in-depth coverage of the application lifecycle. It details how lifecycle events can be utilized to ensure resources are used effectively.
provides an in-depth review of security. It describes how enhanced security can slow down an app and discusses what can be done for an effective trade-off.
covers testing, and performance testing in particular. It also discusses continuous integration and automation.
discusses instrumentation and analytics, and how it can be used to collect performance-related data from apps in production.
provides an outline of the changes in this release and how they impact the code you write from the perspective of performance.
Code snippets are provided throughout the book where applicable. Several of these snippets can be used either as is or with minimal modifications in your app. Other snippets may need to be further adapted to suit your app.
Each chapter also provides a set of best practices associated with the topic. It may not always be possible to follow all of the best practices in a single app. The decisions of which ones you want to trade off against others will be based on your apps requirements.
Online Resources
This book refers to several online blogs, articles, tutorials, and other references. The links to those references are provided where applicable. Should you feel any reference has been missed out accidentally, feel free to contact the publisher or the author.
This book also references screenshots from several apps. The apps are copyright of their respective owners. The screenshots have been added for educational and illustrative purposes only.
Conventions Used in This Book
The following typographical conventions are used in this book:
ItalicIndicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width