01.02.2014 Views

Objective-C Fundamentals

Objective-C Fundamentals

Objective-C Fundamentals

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Using Xcode to develop a simple Coin Toss game<br />

7<br />

1.2.2 Expecting an unreliable internet connection<br />

In this age of cloud computing, a number of iOS applications need connectivity to the<br />

internet. The iOS platform provides two main forms of wireless connectivity: local area<br />

in the form of 802.11 Wi-Fi and wide area in the form of various cellular data standards.<br />

These connection choices provide a wide variability in speed, ranging from 300<br />

kilobits to 54 megabits per second. It’s also possible for the connection to disappear<br />

altogether, such as when the user puts the device into flight mode, disables cellular<br />

roaming while overseas, or enters an elevator or tunnel.<br />

Unlike on a desktop, where most developers assume a network connection is<br />

always present, good iOS applications must be designed to cope with network connectivity<br />

being unavailable for long periods of time or unexpectedly disconnecting. The<br />

worst user experience your customers can have is a “sorry, cannot connect to server”<br />

error message while running late to a meeting and needing to access important information<br />

that shouldn’t require a working internet connection to obtain.<br />

In general, it’s important to constantly be aware of the environment in which your<br />

iOS application is running. Your development techniques may be shaped not only by<br />

the memory and processing constraints of the device but also by the way in which the<br />

user interacts with your application.<br />

That’s enough of the background information. Let’s dive right in and create an<br />

iOS application!<br />

1.3 Using Xcode to develop a simple Coin Toss game<br />

Although you might have grand ideas for the next<br />

iTunes App Store smash, let’s start with a relatively simple<br />

application that’s easy to follow without getting<br />

stuck in too many technical details, allowing the unique<br />

features of the development tools to shine through. As<br />

the book progresses, we dig deeper into the finer points<br />

of everything demonstrated. For now the emphasis is on<br />

understanding the general process rather than the specifics<br />

of each technique.<br />

The application you develop here is a simple game<br />

that simulates a coin toss, such as is often used to settle<br />

an argument or decide who gets to go first in a competition.<br />

The user interface is shown in figure 1.2 and consists<br />

of two buttons labeled Heads and Tails. Using these<br />

buttons, the user can request that a new coin toss be<br />

made and call the desired result. The iPhone simulates<br />

the coin toss and updates the screen to indicate if the<br />

user’s choice is correct.<br />

In developing this game, the first tool we need to<br />

investigate is Xcode.<br />

Figure 1.2<br />

game<br />

Coin Toss sample

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!