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

Creating a framework


As you know, sometimes we have code that is meant to be shared between an application, and the best way to do this is to create a framework. In this case, we are going to create a framework which should contain a customized view. For this recipe, we are going to add only one view. This view will be painted with a gradient. This way, you can change your application's background easily.

Getting ready

Create a new project called CustomViewsFramework. To do this, go to File | New | Project, and then choose the Framework and Library section. Click on the Cocoa Touch Framework option, as shown in the following screenshot:

Select Swift as the project language.

How to do it...

Now, follow these steps to create a framework:

  1. Start adding a new file to your project. In this case, you can choose the Cocoa Touch Class option from the Source section, as shown here:

  2. Now you have to write the new class name, let's call it CVGradientView. Also make sure that a subclass of UIView is selected...