Book Image

Swift Cookbook

By : Cecil Costa, Cecil Costa
Book Image

Swift Cookbook

By: Cecil Costa, Cecil Costa

Overview of this book

Table of Contents (18 chapters)
Swift Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Writing into a log file


This recipe is about a very simple and also a very common pattern design: the Singleton pattern. The idea of this pattern is to have an object with only one instance. You've already used this pattern in Swift or Objective-C, for example, when you used UIDevice or UIApplication.

For this recipe, we will create an object that will write out logs into a file. Note that it doesn't matter where we are in our application code, we should write only into one single file using one single object.

Getting ready

As we will write into a file, probably you would like to see its contents after running the application. Before we start, let's check whether we are able to see the destination folder.

If you use the simulator, open the Finder window and go to your home directory; you can use the shortcut command + shift + H. If you can't see a folder called Library, you have to press command + J to show the view options. Now, check the Show Library Folder option, as shown in the following...