Book Image

Mastering macOS Programming.

By : Stuart Grimshaw, Gregory Casamento
Book Image

Mastering macOS Programming.

By: Stuart Grimshaw, Gregory Casamento

Overview of this book

macOS continues to lead the way in desktop operating systems, with its tight integration across the Apple ecosystem of platforms and devices. With this book, you will get an in-depth knowledge of working on macOS, enabling you to unleash the full potential of the latest version using Swift 3 to build applications. This book will help you broaden your horizons by taking your programming skills to next level. The initial chapters will show you all about the environment that surrounds a developer at the start of a project. It introduces you to the new features that Swift 3 and Xcode 8 offers and also covers the common design patterns that you need to know for planning anything more than trivial projects. You will then learn the advanced Swift programming concepts, including memory management, generics, protocol orientated and functional programming and with this knowledge you will be able to tackle the next several chapters that deal with Apple’s own Cocoa frameworks. It also covers AppKit, Foundation, and Core Data in detail which is a part of the Cocoa umbrella framework. The rest of the book will cover the challenges posed by asynchronous programming, error handling, debugging, and many other areas that are an indispensable part of producing software in a professional environment. By the end of this book, you will be well acquainted with Swift, Cocoa, and AppKit, as well as a plethora of other essential tools, and you will be ready to tackle much more complex and advanced software projects.
Table of Contents (28 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Dedication
Preface
18
LLDB and the Command Line

Preface

This book will take your Swift programming skills to a level at which you can work as a professional software engineer, using a step-by-step approach, ensuring that the introduction of each new concept is preceded by a thorough understanding of those preceding it.

The book covers a range of technologies, particularly those that you'll typically need, if not on day one of a new project (or a new job), then at least pretty soon after. These include not just Apple's Xcode, but also the Terminal app, Git version control, package management, the Swift REPL, and the LLDB debugger, all of which are essential skills.

Each chapter focuses on a particular topic or technology, giving you a deep dive into the skills and know-how that will take your work to a professional standard, in terms of code quality, maintainability, and robustness. This entails general topics, such as programming paradigms and design patterns, a general look at the Cocoa frameworks and their place in the macOS ecosystem, and of course specific technologies around networking, storage, and advanced graphics and animation.

Furthermore, a significant portion of the text is devoted to such thorny issues as concurrency, asynchronous programming, and error handling.

By the end of this book, you will be able to confidently approach projects of much greater size and complexity, and be well placed to comfortably deal with the various issues that all programming inevitably brings with it.

Coding is a never-ending journey. This book aims to get you on the right track, and a fair way along it.

What this book covers

Chapter 1, Hello macOS, explores the context in which the rest of the book is set and takes a look at developing for Apple platforms in general, and the direction that development is heading in.

Chapter 2Basic Swift, takes a broad, high-level view of the Swift programming language.

Chapter 3, Checking out the Power of Xcode, introduces some pro-orientated aspects of this powerful, integrated Development Environment created by Apple.

Chapter 4, MVC and Other Design Patterns, covers a number of ways to help you plan your projects, from high-level conceptual down to the benefits offered by different styles of programming at the code level.

Chapter 5, Advanced Swift, investigates some of Swift's more powerful language features and idioms.

Chapter 6, Cocoa Frameworks - The Backbone of Your Apps, covers the large palette of ready-written framework code that relieve many of the burdens of low-level coding and boilerplate.

Chapter 7, Creating Views Programmatically, is concerned with giving you total control of your user interface, by moving beyond the constraints of visual UI editing.

Chapter 8, Strings and Text, looks at how to master the all-important textual features that are part of nearly every app you'll write for macOS.

Chapter 9, Getting More from Interface Builder, gets you through the maze of functionality offered by Apple's user interface creation tool.

Chapter 10, Drawing on the Strength of Core Graphics, drops us down to some low-level drawing routines, when the preconfigured UI offerings just aren't enough.

Chapter 11, Core Animation, takes you to the heart of what makes macOS such a polished and visually engaging platform.

Chapter 12, Handling Errors Gracefully, deals with the various tools you have at your disposal to handle all eventualities in your app, to produce a smooth and frustration-free user experience.

Chapter 13, Persistent Storage, introduces some of the most commonly used scenarios for storing data on disk.

Chapter 14, The Benefits of Core Data, takes you deeper into structured data persistence, keeping that critical user data organized and quickly accessible.

Chapter 15, Connect to the World - Networking, looks at connecting your code to the Internet, using the web session frameworks that Cocoa provides.

Chapter 16, Concurrency and Asynchronous Programming, aims to set some best practices, as well as investigate the appropriate tools, for dealing with time-sensitive data flows.

Chapter 17, Understanding Xcode's Debugging Tools, helps you master some of the most important tools at our disposal--Xcode's debugging features--for those moments when it doesn't go quite like your plan.

Chapter 18, LLDB and the Command Line, takes you into, and demystifies, working in the terminal, where all the really good stuff lives.

Chapter 19, Deploying Third - Party Code, helps you understand the role of third-party frameworks and libraries, and how to productively integrate them into your codebase.

Chapter 20, Wrapping It Up, gets your code from your hard drive to the App Store, avoiding the most common pitfalls along the way.

What you need for this book

To create and build the code presented here, you will need nothing more than Apple’s Xcode software package, which you can download for free in the App Store, and a Mac to run it on. A number of other tools are introduced, such as the OS X Terminal app, which are already installed on your Mac.

Testing the code can be done on any installation of macOS.

Who this book is for

If you have intermediate knowledge of programming in Swift and are looking for the best way to take your development skills to a professional level, this book is just the right one for you.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "But what if we want to make changes to, say, the app's Build Settings, or even its Info.plist file? Can we do that too?"

A block of code is set as follows:

 cosmicDoor.shadowColor = .gold 
 cosmicDoor.shadowOffset = CGSize(width: 5.0, height: -5.0) 
 cosmicDoor.shadowRadius = 15.0 
 cosmicDoor.shadowOpacity = 1.0 

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

  override func viewDidLoad() 
  { 
    super.viewDidLoad() 
    customView.wantsLayer = true
    setUpButton()
  } 

 

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Click Options, and ensure that Copy Items if Needed is ticked." 

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

 

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Mastering-macOS-Programming. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/MasteringmacOSProgramming_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.