Home Mobile Application Development in iOS 7

Application Development in iOS 7

By Kyle Begeman
books-svg-icon Book
eBook $18.99 $12.99
Print $29.99 $17.98
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $18.99 $12.99
Print $29.99 $17.98
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Xcode 5 – A Developer's Ultimate Tool
About this book
Publication date:
May 2014
Publisher
Packt
Pages
126
ISBN
9781783550319

 

Chapter 1. Xcode 5 – A Developer's Ultimate Tool

With the release of iOS 7, Apple has also provided developers with a completely updated version of Xcode, that is, its Integrated Development Environment (IDE). Xcode 5 is a major step forward, complete with more tools and features available than ever before.

Understanding the powerful features of your IDE is the key to high productivity and overall ease of development. In this chapter, we will explore all these new features and learn how they will assist you in writing your apps for iOS 7.

 

The new user experience


Xcode 5 features many welcomed changes to its overall user experience in the form of subtle design enhancements and under-the-hood optimization. Take a few minutes to play with the new IDE, and you will see that although not much has moved, the cleaner UI provides a much less distracting environment to work in. Shorter toolbars and easy-to-see highlighted buttons help keep your content front and center.

The following screenshot shows how the window of the new IDE looks:

Features such as Open Quickly have been trimmed down in size, yet improved in functionality. Navigating to File | Open Quickly or using the keyboard shortcut command + shift + O will open a simplified single-line search bar in the middle of your screen. As you type an option, search results are returned much more quickly and prioritized based on relevance. Each result also features detailed data on your query such as the file and line number. The following screenshot shows an example of search results:

For a more refined search, you may want to select the search navigator from the navigator panel or use the keyboard shortcut command + 3. Typing a search query and pressing enter will prompt Xcode 5 to perform a project-wide search by default. The results will be displayed in the navigator below the search bar, and also includes new options for refinement. Selecting the In Project button (here, Project is the name of your project) will allow you to specify individual folders to perform the search in. For even more flexibility, the new search navigator will allow you to build custom search scopes that can be saved for future usage. The following screenshot shows the difference between when we do and when we do not select the In FoodAndMe button (in this case, FoodAndMe is the project name):

 

Top-level documentation


Apple provides some of the most in-depth SDK documentation of any development platform. Access to this documentation is possibly one of the most important aspects of iOS development. Previous versions of Xcode always had access to documentation; however, Xcode 5 takes a more accessible approach with its top-level documentation. It's important to note that an Internet connection is required unless you predownload the documentation from Apple. This can be done by navigating to Xcode | Preferences | Downloads.

Go to the menu bar and navigate to Help | Documentation and API Reference. Xcode 5 will show a separate window that has been designed to streamline the search and display of all of the documentation. Apple has built this documentation to work for you. As you type, Xcode will display suggestions in the form of API references, SDK guides, and even Sample Code related to your search.

The new documentation view also provides support for tabs, allowing you to view multiple pieces of documentation simultaneously. As you browse through the results, you may see a dynamic table of contents by clicking on the table of contents button immediately to the left-hand side of the search bar. The table of contents will automatically update based on the document you are currently viewing.

Additionally, the new documentation has built-in bookmarking, which allows you to save your most frequently viewed resources. To the right of the search bar, you will see a share button. Clicking on this button will show a menu with options to share or bookmark the current reference.

You may have also noticed a small bookmark icon on the left-hand side of each title or heading while scrolling through the documentation. You can even save specific sections of any API reference rather than saving the entire document. All of your bookmarks can be viewed in the navigator by clicking on the navigator button immediately on the left-hand side of the table of contents button. This view will also allow you to browse the entire documentation library at a glance. Combine this with the previous ability of pressing the alt key and clicking on any code to display an inline summary and linking from the code to full documentation, and then you'll have robust documentation integration!

 

Debugger and debug gauges


Debugging with Xcode 5 has been greatly improved thanks to many new features added to the debugger. Apple has completely switched from the previous GDB engine to the much more powerful LLDB engine. This allows breakpoint flexibility, inline variable previews, and the finding of variable values more easily.

If you have ever debugged a project using breakpoints, you will notice some changes in the way Xcode 5 manages its breakpoints. Breakpoints are still created by clicking directly on the required line number. These breakpoints can then be enabled or disabled by clicking on them directly or using the breakpoints button that has been moved to the debug toolbar found at the bottom of the Xcode window.

Each breakpoint may also be configured to respond conditionally. By default, code will stop once it reaches a breakpoint. Once you set conditions, however, breakpoints will be ignored unless these conditions are met. You can edit these conditions by right-clicking on an individual breakpoint and selecting Edit Breakpoint. From here, set your conditions and resultant actions. These actions can include logging a message to the console, running an AppleScript or Shell Script, and even playing a sound.

Another great feature of Xcode 5's debugger is the ability to preview variables and objects during debugging using data tips. While debugging your application, hover your mouse over a variable and its value will automatically appear below your cursor. This works for standard data types, such as strings, numeric types, and Boolean types.

Data tips are very powerful when it comes to objects as well. For instance, while in debug mode, hover your mouse over an image, and a summary of information will appear about this object. Selecting the eye-shaped icon will allow you to preview the actual image right in code, as shown in the following screenshot:

Properly debugging any application also involves monitoring system resources to ensure your code is as optimized as possible. Xcode 5 introduces debug gauges, a lightweight and embedded version of some useful instruments' tools. Because debug gauges are integrated into Xcode 5, they are able to run alongside the application at all times while allowing you to observe CPU, Memory, iCloud, Energy, and OpenGL ES resources.

Debug gauges can be found through the debug navigator and will begin running automatically once you run a project. The previously mentioned resources are displayed in an easy-to-read visual graph so that you can monitor your application's performance at a glance and in real time. Additionally, access to the complete instruments software is just a single click away, which is achieved by clicking on the Profile in Instruments button shown in the following screenshot:

 

Automatic configuration with accounts and capabilities


Apple provides a wide variety of useful services that can be included in any application. Enabling your application to support these services has always been a hassle due to the number of tasks a developer is required to manually set up. These include adding entitlements, such as the App ID, linking frameworks to the project, and adding required fields to the projects .plist file. Additionally, each of these services has its own requirements, which means that supporting multiple services would require different steps to complete.

With the introduction of Xcode 5, Apple has made these struggles a thing of the past using automatic configuration. With automatic configuration, all a developer needs is an Apple ID linked to a developer account.

Navigate to Xcode | Preferences and select the Accounts section (new in Xcode 5). From here, you can add all your Developer Program Apple IDs and view details related to each account. Clicking on the + button located on the left-hand side panel will give you the option to add a new Apple ID. Doing so will provide a direct connection between Xcode 5 and the Apple Developer Portal. Once logged in, click on the View Details... button at the bottom-right corner of the screen. A new window will appear with details of all code-signing identities and provisioning profiles attached to the selected account.

Under the General tab in the project editor, you will see a new option, Team, found in the Identity section. Selecting this option will show you a list of identities related to the account we previously added. By selecting your respective signing identity, Xcode 5 will be able to verify whether you have all proper provision profiles and even offer to create them for you if required.

Potentially, the biggest advancement provided by automatic configuration is the Capabilities tab (new in Xcode 5) found in the project editor. This streamlined approach will allow you to configure specific platform features, such as iCloud, In-App Purchases, and Game Center, without having to visit the developer portal as shown in the following screenshot. Xcode 5 will automatically configure the provisioning profile, add App ID entitlements, and link all required frameworks for you, automatically:

If you prefer to set up your features and capabilities the old way, you may still do so in the Apple Developer Portal.

 

Source control


Source control is widely used by large teams and individual developers alike. It provides an extremely useful way to track changes to code and revert back to stable builds of a project with version control. Teams of developers may work separately on individual components by creating and managing a copy of the code (called a branch) without overwriting another team member's code. The change will later be merged while simultaneously tracking all the changes made to the code base.

Source control is not a new feature of Xcode 5; however, Apple has decided to provide easier access to its functionality by creating a top-level menu item. Selecting it will display a drop-down menu with one-click access to most of the source control commands, such as commit, push, and pull. Hovering over Working Copies will open a new submenu that allows you to switch between branches, create a new branch, or merge branches. The following screenshot shows this submenu:

In addition to local source control on your computer, Xcode 5 also supports the ability to connect directly to remote repositories hosted on popular sites, such as GitHub. Open preferences and navigate to the Accounts tab once again. This time, after clicking on the + button, select Add Repository. Once you have entered the proper repository address, Xcode 5 will connect the repository, thus allowing you to access it remotely.

 

Asset catalogs


Every project you create will contain at least a few image files in the form of launch images and application icons as well as other UI elements. Asset catalogs serve two major purposes in Xcode 5. These include automation of icon and launch image naming conventions and grouping image files together in a single location.

Asset catalogs are represented as a separate group with a blue folder in the project navigator. By default, each new project created will include the default Images.xcassets item. You may also create your own asset catalogs for further organization based on personal preference.

Xcode 5 requires each of the launch image files and icon image files to be named appropriately based on the device and/or resolution the image will be used for. When selecting the Images.xcassets item, you will see a number of empty slots waiting for images to be added. Each slot has a description of what image it holds. Dragging from your computer into Xcode 5 on the respective slot will add the image to your project and automatically configure all the naming conventions. The following screenshot shows the Asset Catalog window:

If you wish to add any additional images related to your project, you can simply drag-and-drop them into the Asset Catalog window, and Xcode 5 will take care of the rest. Both high-resolution (2x) and standard-resolution (1x) image files will be grouped together in their own image set with a common name. You still must provide both the low-resolution and high-resolution images yourself. Xcode 5 does not automatically scale them for you: it simply groups them. The value for this name can be changed to any value and will be used in code to access the associated images regardless of the actual filename.

 

Quick build device selection


Developing applications for multiple devices requires consistent device-specific testing. The iOS simulator included in the iOS SDK provides simulation for all Apple devices. With Xcode 5, selecting the proper device to build for has also been streamlined into a single drop-down option found on the toolbar.

Clicking on the name of the current device on the left of the toolbar will provide a drop-down menu. Any and all physical devices connected to your computer will appear on the top of the list (you may have to scroll up to see them), and all standard iOS simulator devices will appear below.

Simply select the device you wish to test for, and click on Run. The simulator will launch and switch to the selected device. The following screenshot lists the devices in the drop-down menu:

 

Storyboard previews


Up until now, writing applications that supported previous versions of iOS mostly consisted of updating API calls and minor coding conventions. With iOS 7, Apple has drastically changed the design of all standard UI objects. Knowing the size, position, and layout of all objects for both iOS 7 and previous versions is very important to maintaining a consistent user experience. This is where storyboard previews come in.

In order to use storyboard previews, you must select the assistant editor and navigate to the view you wish to preview (usually a .xib or .storyboard file). Select the Related Files menu option, navigate to Preview, and select the .xib or .storyboard file you wish to preview, as shown in the following screenshot:

You will see an identical preview of your view on the right-hand side of the assistant editor. In the bottom-right corner of the view, you will see a button that says iOS 7.0 and Later. Click on it, and then select iOS 6.1 and Earlier as shown in the following screenshot:

Your view will now display all of its UI elements as they will appear in iOS 6 or earlier. This is a very handy tool if you wish to make your app backwards compatible.

 

Summary


Xcode 5 has more features for developers than ever before, and each tool is designed to give you a more efficient experience while building the best quality apps possible. In this chapter, we learned how to use all of these features, from new debugging tools to automatic configuration. Although we covered a large portion of new Xcode 5 features, you should visit the following link to view Apple's documentation on what's new in Xcode 5: https://developer.apple.com/library/mac/releasenotes/DeveloperTools/RN-Xcode/Introduction/Introduction.html

With each new iOS SDK release, Apple includes some minor and some major updates to the Objective-C programming language. In the next chapter, we will cover the changes made to the Foundation Framework, possibly the most important framework in all of iOS development!

About the Author
  • Kyle Begeman

    Kyle Begeman is a self-taught programmer, entrepreneur, and educator. With over 6 years of experience in iOS development, Kyle has produced multiple applications personally and professionally (usually with large businesses). Kyle also produces educational videos and courses for others to learn how to program. A self-proclaimed nerd living in Silicon Valley, Kyle spends most of his free time listening to and playing music while thinking up the next great project. You can learn more about Kyle and his work by visiting www.kylebegeman.com.

    Browse publications by this author