Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Application Development in iOS 7
Application Development in iOS 7

Application Development in iOS 7:

eBook
$16.99 $18.99
Paperback
$29.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
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

Application Development in iOS 7

Chapter 2. Foundation Framework – Growing Up

In this chapter, we will learn about modules and how they change the way we import frameworks into our files. We will cover both, the new and the old classes of the Foundation Framework, starting with the brand new NSProgress class. We will see some of the major improvements to the existing classes including NSArray and the firstObject method, NSTimer's new property for managing tolerance, the additional encodings now supported by NSData, and lastly new ways to manage URLs with NSURLUtilities. Let's get started!

Why Foundation matters


Foundation is the core framework of Objective-C. Without it, developing iOS applications would not be possible. Foundation defines the base layer of all classes, as well as functionality for basic data types, including strings, arrays, and dictionaries.

Changes made to the Foundation Framework can range from minor enhancements to the introduction of completely new classes. iOS 7 is no exception to this and Apple has provided some great new features that we will explore in this chapter.

Modules


While developing applications using Xcode and the iOS SDK, you may have noticed that it has never been a requirement to import commonly used header files, such as UIViewController.h or UIView.h.

Open any file in any project, and navigate to any view-controller based .h file in the project. The very first line of code will read as follows:

#import <UIKit/UIKit.h>

Tip

Downloading the example code

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

As an iOS developer, you have probably written hundreds of #import statements in any one project. When the compiler reaches an import statement, it literally inserts every line of code found in the imported header file. In the previous example of the first line of code, UIKit.h imports all header files available in the UIKit Framework...

NSProgress


iOS 7 introduces a completely new class to the Foundation framework, NSProgress. Using NSProgress involves treating each task of an action as a milestone of completion. By doing so, you, the developer, can track progress directly in code and perform individual tasks for each milestone.

For instance, to perform a particular action, you may require four separate tasks to be completed. Each task is capable of monitoring its own progress, and will report once the task is complete. In our example, this would increase the percent of completion to 25.

NSProgress uses Key Value Observing (KVO) to provide notifications related to progress. These notifications can be used to update a UI component displaying progress to the user, such as a progress bar or label. The following code is a very simple implementation that demonstrates working with NSProgress to report progress in a localized manner:

NSArray *data = @[@"Data 1", @"Data 2", @"Data 3", @"Data 4"];

  self.dataProgress = [NSProgress...

NSArray


When using NSArray, you must ensure that all supplied indexes are within range and not beyond the length of the array. When retrieving an element using an index, the index must be between zero and a number (the number being the total items in the array); otherwise, an exception will be thrown. A common use case of this involves grabbing the first or last object from an array.

NSArray has always had the following method to obtain the last object:

- (id)lastObject;

Previously, grabbing the first object of an array required checks to ensure that the index was within the bounds of the array, as shown in the following code snippet:

- (id)firstObjectInArray:(NSArray *)array {

  if (array.count > 0) {
    return array[0];
  }

}

Although the preceding example is rather small, you can see how more complex implementations can be complicated and time consuming. Thankfully, with iOS 7, Apple has finally made public a previously private method for NSArray to grab the first object:

- (id)firstObject...

NSTimer


It is a common practice to perform periodic tasks using NSTimer. The following is an example use of NSTimer to perform a task in two-second intervals and repeats:

[NSTimer scheduledTimerWithTimeInterval:2.0
  target:self
  selector:@selector(targetMethod:)
  userInfo:nil
  repeats:YES];

The issue with this method is that the CPU is consistently active in order to perform the desired task repeatedly. When using multiple timers at once, it is possible (although unlikely) that it may reduce the performance of the CPU for the rest of your application. It is always best practice to run tests on your applications to find such possibilities and use safeguards wherever possible.

Apple has added a new tolerance property to NSTimer to reduce the strain on the CPU when using NSTimers. This property will tell the application how late a timer is allowed to fire when it has surpassed its scheduled interval. As a result, the application will be able to group actions together to reduce CPU strain.

This...

NSData


Every application uses data in some way or another. In some instances, you may require the ability to manipulate individual bytes of data. NSData encapsulates these raw bytes to allow for easy manipulation using built-in methods.

With iOS 7, NSData now adds support for Base64 encoding and decoding; a group of ACSII format binary-to-text encoding schemes. These schemes are most commonly used to transfer data between media that only support text-based data transfer. Encoding images from JSON-based responses from a web API is the most common use for these schemes.

Prior to iOS 7, developers were required to use a third-party library or build their own from scratch. Apple has made it exceptionally easy to use these encoding methods with the following methods:

- (id)initWithBase64EncodedData:(NSData *)base64Data 
  options:(NSDataBase64DecodingOptions)options;

- (NSData *)base64EncodedDataWithOptions:
  (NSDataBase64EncodingOptions)options;

- (id)initWithBase64EncodedString:(NSString *...

NSURLUtilities


The Foundation Framework includes many different methods related to handling URLs; however, most API's related to manipulating these URLs are based on NSString because NSURL is an immutable class.

In order to fix this issue, Apple has introduced NSURLComponents to allow for manipulation of URL objects. With NSURLComponents, NSURL can be treated as a mutable object that allows direct manipulation. The following code snippet is an example use case:

NSURLComponents *components = [NSURLComponents componentsWithString:@"http://somewebsite.com"];

components.path = @"/somepath";
components.query = @"queryParameter=parameterValue";

NSLog(@"%@", [components URL]);

Running this code will output the following to the console:

http://somewebsite.com/somepath?queryParameter=parameterValue

Using NSURLComponents, you may now directly manipulate NSURL values without the use of NSString.

Summary


In this chapter, we covered some of the major updates to the Foundation Framework. It is always recommended that you stay up to date with the advancements to Objective-C and Apple's core frameworks. With this knowledge, you now have the tools to build more efficient and better-performing applications!

Now that we have a better understanding of the new features found in Foundation, it's time to start building our application. In the next chapter, we will begin building our interface using the new Auto Layout features in iOS 7.

Left arrow icon Right arrow icon
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 19, 2014
Length: 126 pages
Edition :
Language : English
ISBN-13 : 9781783550319
Category :
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
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 United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Publication date : May 19, 2014
Length: 126 pages
Edition :
Language : English
ISBN-13 : 9781783550319
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 $ 84.98
Application Development in iOS 7
$29.99
iOS and OS X Network Programming Cookbook
$54.99
Total $ 84.98 Stars icon

Table of Contents

8 Chapters
Xcode 5 – A Developer's Ultimate Tool Chevron down icon Chevron up icon
Foundation Framework – Growing Up Chevron down icon Chevron up icon
Auto Layout 2.0 Chevron down icon Chevron up icon
Building Our Application for iOS 7 Chevron down icon Chevron up icon
Creating and Saving User Data Chevron down icon Chevron up icon
Displaying User Data Chevron down icon Chevron up icon
Manipulating Text with TextKit Chevron down icon Chevron up icon
Adding Physics with UIKit Dynamics Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7
(3 Ratings)
5 star 66.7%
4 star 33.3%
3 star 0%
2 star 0%
1 star 0%
Vladimir Fedorov Aug 22, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Apple updates the iOS SDK every year and it is vital to keep up with the changes: they simplify the process of development, make it faster and help you to draw attention to your application.Most books about software development describe the whole set of SDK features; while being useful for a beginner, they rarely explain the exact difference between the previous version of SDK and the current one, making advanced developers fish for this information. “Application Development in iOS 7” is different: it highlights changes in Xcode and iOS SDK that took place since the last year when iOS 6 SDK was presented.The best way get used to this changes is to build a sample application that utilises SDK’s latest methods. The book describes the application development process in a step-by-step manner: from basics of auto layout to gestures and advanced visual effects.“Application Development in iOS 7” is well-structured, each chapter describes one aspect of the development kit update. First chapters unveil new features Xcode got with version 5 and changes in Foundation Framework in a way a good reference book does—introducing every new method with a short consideration on why it was added and how to use it. Another chapter is entirely devoted to the TextKit—a huge improvement in text manipulation since the beginning of iOS and the basis for all text UI elements in iOS 7. UIKit Dynamics, a physics engine that serves gravity, bouncing and other UI effects, is also explained in the book.Weather you’ve already updated your code to support the latest features or are seeking new features to differentiate your product from innumerable items in the AppStore, “Application Development in iOS 7” is a good guide on how to give your application a clearly noticeable iOS 7 look and feel.
Amazon Verified review Amazon
SuJo Aug 23, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Application Development in iOS 7Publisher Link: https://www.packtpub.com/application-development/application-development-ios-7I've not used any of the Apple SDK or anything Apple for that matter, and I found this book extremely helpful. Not only did it help me get started pretty quickly, it helped me get everything setup for development purposes. I found the code in the book to work the first time and I didn't really have any issues with downloading the materials from the publishers website either. I'm not overly critical on finding grammar or other mistakes so long as the code works. I felt the book progressed nicely as it starts with setting up the working environment into creation of projects and then to working examples, which you should tinker with and try to build onto in order to continue your learning.Overall I do agree with the publisher that this book is designed for the novice users, I don't think you'd get much if you were an expert; however you would most likely gain from the updated SDK content offered in this book. I often find myself buying books on things I still don't consider myself excellent with, just to see what changed! Excellent book, great price, .mobi version worked very well, and nothing to complain about here.
Amazon Verified review Amazon
Rock Jun 28, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Apple continually evolves the Xcode platform, the Foundation Framework, updating Objective-C, and so on. Recently announced, they have a new language based off of Objective-C called Swift. I believe this shows how Apple is growing up with their tech and moving it forward. There are a lot of interesting changes here.The book starts off with showing a few nice Xcode features recently added. There is certainly a lot more new features in iOS 7 but it focuses on some of the more significant workflow changes. It accompanies them with some decently written code skeleton examples, pictures, and well written explanations. There are some segments where the book will refer back to iOS 6 and explain how Apple addresses an issue feature with iOS 7, and why its better now.Binding data to the storyboard UI is the “magic sauce” with the iOS development and the book takes you through a very simple app tutorial while simultaneous explaining how its improved. My one complaint about the book would have to be that it seems like “this feature is one of the newest big additions to iOS” is applied to everything. While I said previously there was a good focus on significant changes, it felt like it got to “hey look, you can change font sizes now!” Which apparently is a major request for developers. Kind of ties back to my issue with Apple controlling the platform, I think this wouldn’t have been an issue if people could get more control of it.I also would've loved to have seen some more Physics UI demonstration, but there is some there to get your feet wet.
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 digital copy I get with my Print order? Chevron down icon Chevron up icon

When you buy any Print edition of our Books, you can redeem (for free) the eBook edition of the Print Book you’ve purchased. This gives you instant access to your book when you make an order via PDF, EPUB or our online Reader experience.

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 customercare@packt.com 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 customercare@packt.com 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 customercare@packt.com 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 customercare@packt.com 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 customercare@packt.com 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 customercare@packt.com 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