Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Swift Cookbook
  • Table Of Contents Toc
Swift Cookbook

Swift Cookbook

By : Costa
5 (1)
close
close
Swift Cookbook

Swift Cookbook

5 (1)
By: Costa

Overview of this book

If you are an experienced Objective-C programmer and are looking for quick solutions to many different coding tasks in Swift, then this book is for you. You are expected to have development experience, though not necessarily with Swift.
Table of Contents (13 chapters)
close
close
12
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.
    How to do it...
  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.
    How to do it...
  3. Go to the General tab and scroll down; you can see where you can add the embedded binaries.
    How to do it...
  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.

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Swift Cookbook
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon