Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Mastering Swift
Mastering Swift

Mastering Swift:

eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Mastering Swift

Chapter 1. Taking the First Steps with Swift

Ever since I was 12 years old and wrote my first program in the basic programming language, programming has been a passion for me. Even as programming became my career, it always remained more of a passion than a job, but over the past few years, that passion has waned. I was unsure why I was losing that passion. I attempted to recapture it with some of my side projects but nothing really brought back the excitement that I used to have. Then, something wonderful happened, Apple announced Swift. Swift is such an exciting and progressive language that it has brought a lot of that passion back and made programming fun for me again.

In this chapter, you will learn:

  • What is Swift?
  • What are some of the features of Swift?
  • What are Playgrounds?
  • How do you use Playgrounds?
  • What are the basic syntaxes of the Swift language?

What is Swift?

Swift is Apple's new programming language that was introduced at the Worldwide Developers Conference (WWDC) in 2014 alongside the integrated development environment Xcode 6 and iOS 8. Swift was arguably the most significant announcement at WWDC 2014 and very few people, including Apple insiders, were aware of the project's existence prior to it being announced. It was amazing, even by Apple's standards, that they were able to keep Swift a secret for as long as they did and that no one suspected they were going to announce a new development language.

Swift can be thought of as Objective-C reimagined using modern concepts and safe programming patterns. In Apple's own words, Swift is like Objective-C without the C. Chris Lattner, the creator of Swift, said Swift took language ideas from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list.

At WWDC 2014, Apple really stressed that Swift was Safe by Default. Swift is designed to eliminate many common programming errors, making applications more secure and less prone to bugs. As we look at Swift throughout this book, we will point out many ways in which Swift is safer than not only Objective-C, but also safer than most other modern languages.

The development of Swift started in 2010 by Chris Lattner. He implemented much of the basic language structure with only a few people being aware of its existence. It wasn't until late 2011 that other developers began to really contribute to Swift, and in July of 2013, it became a major focus of the Apple Developer Tools group.

Chris Lattner started at Apple in the summer of 2005. He has held several positions in the Developers Tools group and is currently the Director and Architect of that group. On his home page (http://www.nondot.org/sabre/), Chris notes that Xcode's Playground (more on Playgrounds a little later in this chapter) became a personal passion of his because it makes programming more interactive and approachable. We will be using Playgrounds a lot in the book as a test and experimentation platform.

There are a lot of similarities between Swift and Objective-C. Swift adopts the readability of Objective-C's named parameters and dynamic object model. Swift also provides seamless access to existing Cocoa frameworks. This gives Objective-C developers a certain amount of familiarity when they begin to learn Swift.

While there are a lot of similarities between Swift and Objective-C, there are also significant differences between them as well. Swift's syntax and formatting are a lot closer to Python than Objective-C, but Apple did keep the curly braces. I know Python people would disagree with me, and that is alright because we all have different opinions, but I like the curly braces. Swift actually makes the curly braces required for control statements, such as if and while, and eliminating bugs such as the Goto Fail bug in Apple's SSL library.

Mix and match allows us to create applications that contain both Objective-C and Swift files that can communicate with each other. This allows us to systematically update current Objective-C applications with Swift classes. It also allows us to use current Objective-C libraries/frameworks in our Swift applications.

Tip

Mix and match lets Objective-C and Swift files coexist in the same project. This allows us to begin using Swift without throwing away our existing Objective-C code base or projects.

Swift was also built to be fast. At WWDC 2014, Apple showed a number of benchmarks that showed Swift significantly outperformed Objective-C. Swift uses the LLVM compiler, which is included with Xcode 6 to transform the Swift code into highly optimized native code that is tuned to get the most out of Apple's modern hardware.

If you are an iOS or OS X developer and you are still not convinced that learning Swift is a good idea, then maybe this one paragraph from Apple's Swift page (https://developer.apple.com/swift/) will help convince you:

Swift is a successor to the C and Objective-C languages. It includes low-level primitives such as types, flow control, and operators. It also provides object-oriented features such as classes, protocols, and generics, giving Cocoa and Cocoa Touch developers the performance and power they demand.

The first line in that paragraph that says, "Swift is a successor to the C and Objective-C languages" is the most important line. This line and other Apple documentation tells us that Apple sees the Swift language as its application and systems programming language of the future. While Objective-C is not going away anytime soon, it sounds like it will be taking a backseat to Swift in the very near future.

Swift features

When Apple said that Swift is Objective-C without the C, they are really only telling us half of the story. Objective-C is a superset of C and provides object-oriented capabilities and a dynamic runtime to the C language. This meant that Apple needed to maintain compatibility with C, which limited the enhancements it could make to the Objective-C language. As an example, Apple could not change how the switch statement functioned and still maintains the C compatibility.

Since Swift does not need to maintain the same C compatibility of Objective-C, Apple was free to add any feature/enhancement to the language. This allowed Apple to include the best features from many of today's most popular and modern languages, such as Objective-C, Python, Java, Ruby, C#, Haskell, and many others.

The following chart shows a list of some of the most exciting enhancements that Swift includes:

Swift feature

Description

Type inference

Swift can automatically deduce the type of the variable or constant based on the initial value.

Generics

Generics allow us to write code once to perform identical tasks for different types of objects.

Collection mutability

Swift does not have separate objects for mutable or non-mutable containers. Instead, you define mutability by defining the container as a constant or a variable.

Closure syntax

Closures are self contained blocks of functionality that can be passed around and used in our code.

Optionals

Optionals define a variable that might not have a value.

Switch statement

The Switch statement has been drastically improved. This is one of my favorite improvements.

Multiple return types

Functions can have multiple return types using tuples.

Operator overloading

Classes can provide their own implementation of existing operators.

Before we begin our journey into the wonderful world of Swift development, let's take a detour and visit a place that I have loved ever since I was a kid: The playground.

Playgrounds

When I was a kid, the best part of the school day was going to the playground. It really did not matter what we were playing as long as we were on the playground, I knew it would be fun. When Apple introduced Playgrounds as part of Xcode 6, I was excited just by the name, but I wondered if Apple could make its Playground as fun as the playgrounds from my youth. While Apple's Playgrounds might not be as fun as playing kickball when I was nine years old, it definitely brings a lot of fun back to experimenting and playing with code.

Getting started with Playgrounds

Playgrounds are an interactive work environment that lets us write code and see the results immediately in the sidebars. As changes are made to the code, the results in the sidebar also change in real time. This means that Playgrounds are a great way to learn and experiment with Swift.

Playgrounds also make it incredibly easy to try out new APIs, prototype new algorithms, and demonstrate how code works. We will be using Playgrounds throughout this book to show how our sample code works. Therefore, before we really get into Swift development, let's spend some time learning and getting comfortable with Playgrounds.

If the Swift code does not make a lot of sense right now, do not worry; as we go through the book, this code will begin to make sense. We are simply trying to get a feel of Playgrounds right now.

A Playground has three sections, as follows:

  • Coding Area: This is where you enter your Swift code.
  • Results Sidebar: This is where the results of your code are shown. Each time you type in a new line of code, the results are re-evaluated and the results sidebar is updated with the new results.
  • Timeline Sidebar: This sidebar displays various objects depending on what your code does. Later in this chapter, we will show you how to display an image in the timeline sidebar.

The following screenshot shows how the sections are arranged in a Playground:

Getting started with Playgrounds

Let's start a new Playground. The first thing we need to do is to start Xcode. Once Xcode has started, we can select the Get started with a playground option, as shown in the following screenshot:

Getting started with Playgrounds

Alternatively, we can navigate to File | New | Playground from the top menu bar, as shown in the following screenshot:

Getting started with Playgrounds

Next, we should see a screen similar to the following screenshot that lets us name our Playground and select whether the Playground is an iOS or OS X Playground. For most of the examples in this book, it is safe to assume that you can select either iOS or OS X unless it is otherwise noted.

Getting started with Playgrounds

Finally, we are asked for the location to save our Playground too. After we select the location, the Playground will open up and look similar to the following screenshot:

Getting started with Playgrounds

From the preceding screenshot, we can see that the coding area of the Playground looks like the coding area for an Xcode project. What is different is the sidebar on the right-hand side. This sidebar is where the results of our code are shown. The code in the previous screenshot imports iOS's UIKit framework and sets a variable named str to the string Hello, playground. You can see the content of the str string in the sidebar to the right of the code.

By default, a new Playground does not open the timeline sidebar. You can open it manually by pressing the Command, Option, and Enter keys together. We will show you why the timeline sidebar is so important later in this chapter.

iOS and OS X Playgrounds

When you start a new iOS Playground, the Playground imports UIKit (Cocoa Touch). This gives us access to the UIKit framework that provides the core infrastructure for iOS applications. When we start a new OS X Playground, the Playground imports Cocoa. This gives us access to the OS X Cocoa framework.

What the last paragraph means is, if we want to experiment with specific features of either UIKit or Cocoa, we need to open the correct Playground. As an example, if we have an iOS Playground open and we want to create an object that represents a color, we would use a UIColor object. If we had an OS X playground open, we would use an NSColor object to represent a color.

Showing images in a Playground

As you will see throughout this book, Playgrounds are great at showing the results of code as text in the results sidebar. Playgrounds can also do a lot more than just text; they can also do images, graphs, and display views. Let's take a look at how we would show an image in a Playground. The first thing we need to do is to load the image into the resource directory of our Playground. The following steps show how to load an image into the resource directory:

  1. Let's begin by showing the project navigator sidebar. To do this, in the top menu bar navigate to View | Navigators | Show Project Navigator, or you can use the Command-1 keyboard shortcut. The project navigator looks like this:
    Showing images in a Playground
  2. Next, we need to drag the image into the Resources folder so that we can access it from our code. Once we drag the image file over it, it will appear in the Resources folder.
  3. Now we can access the image that is in our Resources folder with our code. The following screenshot shows how we will do this. The actual code that we use to access the image is not as important at this time as knowing how to access resources within a playground:
    Showing images in a Playground
  4. To view the image, we need to hover our cursor in the results sidebar over the section that shows the width and height of the image. In our example, the width and height section looks like this: w 256 h 256. Once we hover the mouse pointer of the width and height, we should see two symbols, as shown in the following screenshot:
    Showing images in a Playground
  5. We can press either of the symbols to show the image. The one that is shaped like a circle with a plus sign in it will display the image within the playground's code section, while the one that looks like an eye will pop the image up outside of the playground. The following screenshot shows what it looks like if we press the symbol that looks like a circle with a plus sign in it.
    Showing images in a Playground

Displaying graphs in Playgrounds

We can also graph the value of numeric variables over time with the timeline sidebar. This feature is really useful when we are prototyping new algorithms. It allows us to see the value of the variable throughout the course of the calculations. To see how graphing works, take a look at the following Playground:

Displaying graphs in Playgrounds

In this playground, we set the variable j to 1. We then create a for loop that assigns numbers 1 through 5 to the variable i. At each step in the for loop, we set the value of the variable j to the current value of j multiplied by i. The graph in the timeline sidebar shows the value of the variable j at each step of the for loop. We will be covering for loops in detail later in this book.

To bring up the graph, click on the symbol that is shaped like a circle with a dot in it. We can then move the timeline slider to see the values of variable j at each step of the for loop.

What Playgrounds are not

There is a lot more that we can do with Playgrounds, and we have only scratched the surface in our quick introduction here. As we proceed through the book, we will be using Playgrounds for almost all of the sample code and will demonstrate other features of Playgrounds as they are used.

Before we leave this brief introduction, let's take a look at what Playgrounds are not, so we can understand when not to use Playgrounds:

  • Playgrounds should not be used for performance testing: The performance you see from any code that is run in a Playground is not representative of how fast the code will run when it is in your projects.
  • Playgrounds do not support user interaction: Users cannot interact with code that is run in a Playground.
  • Playgrounds do not support on-device execution: You cannot run the code that is present in a Playground outside of the Playground. This means you cannot run it as an external application or on an external device.

Swift language syntax

If you are an Objective-C developer, and you are not familiar with modern languages like Python or Ruby, the code in the previous screenshots probably looked pretty strange. The Swift language syntax is a huge departure from Objective-C, which was based largely on Smalltalk and C.

The Swift language uses very modern concepts and syntax to create very concise and readable code. There was also a heavy emphasize on eliminating common programming mistakes. Before we get into the Swift language itself, let's take a look at some of the basic syntax of the Swift language.

Comments

Writing comments in Swift code is a little different from writing comments in Objective-C code. We still use the double slash // for single line comments and the /* and */ for multiline comments.

What has changed is how we document the parameters and the return value. To document any parameter, we use the :parm: field, and for the return value, we use the :return: field. The following Playground shows examples of both single line and multiline comments to properly comment a function:

Comments

To write good comments, I would recommend using single line comments within a function to give quick one-line explanations of your code. We will then use the multiline comments outside of functions and classes to explain what the function and class does. The preceding Playground shows a good use of comments. By using proper documentation, as we did in the preceding screenshot, we can use the documentation feature within Xcode. If we hold down the option key, and then click on the function name anywhere in our code, Xcode will display a popup with the description of the function. This next screenshot shows what that popup would look like:

Comments

Semicolons

You probably noticed from the code samples so far, that we are not using semicolons at the end of lines. The semicolons are optional in Swift; therefore, both lines in the following Playground are valid in Swift. You can see the results of the code in the results sidebar, as shown in the following screenshot:

Semicolons

For style purposes, it is strongly recommended that you do not use semicolons in your Swift code. If you are really set on using semicolons in your code (I would not recommend it), then I would recommend just being consistent and using it on every line of code; however, Swift will not warn you if you forget them.

Parentheses

In Swift, parentheses around conditional statements are optional, for example, both if statements in the following Playground are valid. You can see the results of the code in the sidebar, as shown in the following screenshot:

Parentheses

For style purposes, it is recommended that you do not include the parentheses in your code unless you have multiple conditional statements on the same line. For readability purposes, it is good practice to put parentheses around the individual conditional statements that are on the same line. See the following Playground for samples:

Parentheses

Curly braces

In Swift, unlike most other languages, the curly bracket is required after statements. This is one of the safety features that are built into Swift. Arguably, there have been numerous security bugs that may have been prevented if the developer would have used curly braces. A good example of this is Apple's Goto Fail bug. These bugs could also have been prevented by other means, as well as unit testing and code reviews, but requiring developers to use curly braces, in my opinion, is a good security standard. The following Playground shows you what error you get if you forget to include the curly braces:

Curly braces

Assignment operator (=) does not return a value

In most other languages, the following line of code is valid, but it probably is not what the developer meant to do:

if (x =1) {
}

In Swift, this statement is not valid. Using an assignment operator (=) in a conditional statement (if and while) will throw an error. This is another safety feature built into Swift. It prevents the developer from forgetting the second equals sign (=) in a comparison statement. This error is shown in the following Playground:

Assignment operator (=) does not return a value

Tip

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. 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.

Spaces are optional in conditional and assignment statements

For both conditional (if and while) and assignment (=) statements, the white spaces are optional. Therefore, in the following Playground, both the i block and j block of code are valid.

Spaces are optional in conditional and assignment statements

Tip

For style purposes, I would recommend adding the white spaces (such as the j block for readability purposes), but as long as you pick one style and be consistent, either style should be acceptable.

Hello world

All good computer books that are written to teach a computer language have a section that shows a user how to write a Hello World application. This book is no exception. In this section, we will show you how to write two different Hello World applications.

Our fist Hello World application will be the traditional Hello World application that simply prints Hello World to the console. Let's begin by creating a new Playground and naming it Chapter_1_Hello_World. The Playground can be either an iOS or an OS X Playground.

In Swift, there are two functions that will print messages to the console. These functions are print() and println(). The print() function will print the textural representation of the object passed to it, while the println() function will also print the textural representation of the object passed to it, and will also add a new line character to the end.

The println() function is overloaded to receive either an object to print or no value, in which case, we will print only a newline character to the console.

Let's add the println() function, as shown in the following Playground, to our Playground to print the Hello World message to the console. We will then need to open the Timeline sidebar (keyboard shortcut: Command-option and Enter) to see what is being printed to the console. Our Playground should look like the following Playground once we are done:

Hello world

As we can see in the Timeline sidebar, our application will print the message Hello World! to the console.

Now, let's see if we can spice this up a bit and include a variable. We will be covering variables a lot more in the next chapter, so, for right now, it is alright if you do not fully understand how variables in Swift work; we mainly want to show you how to include variables in a println() function.

There are two ways in which we can add a string to another string. We can concatenate them or we can include them inline. To concatenate two strings, we use the + operator to add them together. The following code is an example of concatenating two strings:

var stringC = stringA + stringB

To include a string inline, we use a special sequence of characters \( ). The following code shows how to include a string inline with another string:

var name = "Jon"
var stringC = "Hello \(name)"

The following Playground shows examples of how to concatenate strings and how to include strings inline:

Hello world

For the message1 variable, we concatenate the strings together, while for the message2 variable, we include the other strings inline. We then use the prinln() function to display both messages to the console.

Summary

In this chapter, we showed you how to start and use Playgrounds to experiment with Swift programming. We also covered the basic Swift language syntax and discussed proper language styles. The chapter concluded with two Hello World examples. In the next chapter, we will see how to use variables and constants in Swift. We will also look at the various data types and how to use operators in Swift.

Left arrow icon Right arrow icon

Description

If you are a developer that learns best by looking at, and working with, code, then this book is for you. A basic understanding of Apple's tools is beneficial but not mandatory.

What you will learn

  • Prototype and test code in a Playground
  • Understand the basics of Swift, including operators, collections, control flows, and functions
  • Create and use Classes, Structures, and Enums, including objectoriented topics such as inheritance, protocols, and Extensions
  • Dwell into Subscripts, Optionals, and closures with realworld scenarios
  • Employ Grand Central Dispatch to add concurrency to your applications
  • Study the ObjectiveC interoperability with mix and match
  • Access network resources using Swift
  • Implement various standard design patterns in the Swift language
Estimated delivery fee Deliver to Colombia

Standard delivery 10 - 13 business days

$19.95

Premium delivery 3 - 6 business days

$40.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 29, 2015
Length: 358 pages
Edition : 1st
Language : English
ISBN-13 : 9781784392154
Vendor :
Apple
Category :
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Colombia

Standard delivery 10 - 13 business days

$19.95

Premium delivery 3 - 6 business days

$40.95
(Includes tracking information)

Product Details

Publication date : Jun 29, 2015
Length: 358 pages
Edition : 1st
Language : English
ISBN-13 : 9781784392154
Vendor :
Apple
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 158.97
Swift Cookbook
$54.99
Mastering Swift
$54.99
Learning Swift
$48.99
Total $ 158.97 Stars icon
Banner background image

Table of Contents

16 Chapters
1. Taking the First Steps with Swift Chevron down icon Chevron up icon
2. Learning about Variables, Constants, Strings, and Operators Chevron down icon Chevron up icon
3. Using Collections and Cocoa Data Types Chevron down icon Chevron up icon
4. Control Flow and Functions Chevron down icon Chevron up icon
5. Classes and Structures Chevron down icon Chevron up icon
6. Working with XML and JSON Data Chevron down icon Chevron up icon
7. Custom Subscripting Chevron down icon Chevron up icon
8. Using Optional Type and Optional Chaining Chevron down icon Chevron up icon
9. Working with Generics Chevron down icon Chevron up icon
10. Working with Closures Chevron down icon Chevron up icon
11. Using Mix and Match Chevron down icon Chevron up icon
12. Concurrency and Parallelism in Swift Chevron down icon Chevron up icon
13. Swift Formatting and Style Guide Chevron down icon Chevron up icon
14. Network Development with Swift Chevron down icon Chevron up icon
15. Adopting Design Patterns in Swift Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(2 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Just Me Dec 20, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great book for learning Swift 1.x but if your are looking for a book on Swift 2 get the Mastering Swift 2 book
Amazon Verified review Amazon
Amazon Customer Dec 04, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Mastering Swift is a very clear and concise. Really nice to anyone who wants to jump from Objective C to Swift or start from the scratch.All the explanations are followed with clear example.You won't regret it.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact [email protected] with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at [email protected] using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on [email protected] with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on [email protected] within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on [email protected] who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on [email protected] within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela