Book Image

Swift Cookbook

Book Image

Swift Cookbook

Overview of this book

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

Using Swift project options


Xcode projects comes with lots of options. Here, we will know some of them, mainly the Swift-specific ones.

Getting ready

To do this recipe, just create a new project, as shown in the previous recipe.

How to do it...

Follow these steps for changing some Swift options:

  1. Once you've created a project, click on the navigator project icon or press command + 1 if you prefer a keyboard shortcut, then click on your project icon (the first icon). Now, click on Build Settings.

  2. Look for Embedded content contains swift code; In this case, we will select NO, but of course, if you know that there is any extra content created with Swift, you should select YES.

  3. Go to the General tab and scroll down; you can see where you can add the embedded binaries.

  4. Now, look for Optimization Level. Here is where you tell the compiler how much time it should expend trying to make your code faster or compressing it. Usually, when we are developing (debug mode), we set for no optimization (-O0); however, when we are going to create the final product (release mode), we will usually set an optimization level such as-Os, which means fastest and smallest.

    Note

    Sometimes, with Objective-C, when you used to set a high level of optimization, the debugger used to loose some of the variable values. I haven't seen this phenomenon with Swift yet, but it's good to have it in mind.

  5. Another important option is Import paths. This tells Swift where it should look for Swift modules. If you are linking your project with external libraries, you may need to specify where the module.map file is. If you have more than one path to search, you need to set them one per line. If you have different paths for debug and release, you can still use variables such as $(CONFIGURATION) or $(TARGET).

Tip

You can use absolute or relative paths, but I would give preference to the relative ones.

How it works...

Changing settings is something that you have to do mainly when your project starts growing. There are some options that you set differently for debug and release configurations.

There's more...

Xcode has a lot of configuration settings; showing all of them would be out of the scope of this book. I recommend that you at least look at some of them, mainly if you want to work with big projects. My main recommendation here is: do not change your settings without synchronizing with the other members of your team (mainly with the project manager). If you cause a conflict with the VCS, it could be hard work to fix it.