Read iOS Programming: The Big Nerd Ranch Guide, 3/e (Big Nerd Ranch Guides) Online

Authors: Aaron Hillegass,Joe Conway

Tags: #COM051370, #Big Nerd Ranch Guides, #iPhone / iPad Programming

iOS Programming: The Big Nerd Ranch Guide, 3/e (Big Nerd Ranch Guides) (101 page)

 

Finally, we can test our work. Build and run
Nerdfeed
on a device. Click
Stop
in
Xcode
, and then build and run on another device. Restart the application on the first device, and select a row from the table view. After a few moments, you will see the checkmark appear in that row on the other device!

 

One thing to keep in mind when using iCloud-capable applications is that deleting an application does not delete the data from Apple’s servers. Sometimes when developing an iCloud application, you will need to change the structure of your data and delete the old data structure from the cloud.

 

To delete an application’s data from the cloud, open the
Settings
application on the device and select
iCloud
. Next, select
Storage & Backup
near the bottom of the next screen and then
Manage Storage
. You will see a screen that looks like
Figure 30.8
.

 

Figure 30.8  Managing iCloud Storage

 

Every iCloud-capable application on a device will appear on this screen under
Documents & Data
. When developing an application, its name is not yet registered with Apple’s servers, so it will appear as
Unknown
. To delete the data associated with an application you are developing, tap the
Unknown
row. Then, tap the
Edit
button. A big
Delete All
button will appear – tap it to remove the data from the iCloud servers.

 

You only have to delete data from iCloud’s storage from one device because all devices share the same data.

 
For the More Curious: iCloud Backups

Although not an explicit feature of iCloud, iOS supports backing up the contents of a device in the cloud. Part of the backup process synchronizes the
Documents
and
Library/Preferences
directories of each application sandbox. This is pretty neat, but you can’t go hog wild. This ability to back up data in
Documents/
in the cloud has led to a new requirement for applications: you can’t store too much data in the
Documents
directory on pain of your application being rejected by the App Store.

 

Of course,

too much data

is frustratingly vague, but the general rule is only store in
Documents/
what really needs backing up and not what can be recreated. Data that can be recreated should be stored in
Library/Caches/
instead of
Documents/
.

 

However, there is a problem with this rule. The system can purge the contents
Library/Caches/
when an application is running low on disk space, and it can do so without warning. Now, if an application can recreate its caches from another server, it’s not a big deal if this directory gets purged – you just download the content again. However, some applications cache content for offline use. For example, an application could download web articles so that the user can read them on a plane. If the application is offline, data that gets purged can’t be recreated.

 

If you need to store potentially large amounts offline content indefinitely, the fix is to put the data in
Documents/
and
set a special flag that prevents the file or the folder and its contents from being backed up. This protects the data from being purged and keeps the App Store happy. You set this flag like so:

 
NSArray *docsDirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                        NSUserDomainMask,
                                                        YES);
NSString *path = [[docsDirs objectAtIndex:0]
                        stringByAppendingPathComponent:@"somefile"];
[data writeToFile:path atomically:YES];
NSURL *url = [NSURL fileURLWithPath:path];
[url setResourceValue:[NSNumber numberWithBool:YES]
               forKey:NSURLIsExcludedFromBackupKey
                error:nil];
 

The important bit here is the key
NSURLIsExcludedFromBackupKey
. This key can be set on any URL (file or folder) in an application’s sandbox and prevent it from being backed up. Note that this flag is not the same as the
.nosync
suffix, which prevents a file or folder in a ubiquity container from being synchronized in the cloud.

 
31
Afterword

Welcome to the end of the book! You should be very proud of all your work and all that you have learned. Now, there’s good news and bad news:

 
  • The good news:
    The stuff that leaves programmers befuddled when they come to the iOS platform is behind you now. You are an iOS developer.
 
  • The bad news:
    You are probably not a very good iOS developer.
 
What to do next

It is now time to make some mistakes, read some really tedious documentation, and be humbled by the heartless experts who will ridicule your questions. Here’s what we recommend:

 

Write apps now.
If you don’t immediately use what you have learned, it will fade. Exercise and extend your knowledge. Now.

 

Go deep.
This book has consistently favored breadth over depth; any chapter could have been expanded into an entire book. Find a topic that you find interesting and really wallow in it – do some experiments, read Apple’s docs on the topic, read a posting on a blog or on StackOverflow.

 

Connect.
There is an iOS Developer Meetup in most cities, and the talks are surprisingly good. There are discussion groups online. If you are doing a project, find people to help you: designers, testers (AKA guinea pigs), and other developers.

 

Make mistakes and fix them.
You will learn a lot the days you say,

This application has become a ball of crap! I’m going to throw it away and write it again with an architecture that makes sense.

Polite programmers call this
refactoring
.

 

Give back.
Share the knowledge. Answer a dumb question with grace. Give away some code.

 
Shameless plugs

You can find us both on Twitter, where we keep you informed about programming and entertained about life:
@joeconwaybnr
and
@aaronhillegass
.

 

Keep an eye out for future guides from Big Nerd Ranch. We also offer week-long courses for developers. And if you just need some code written, we do contract programming. For more information, visit our website at
http://www.bignerdranch.com/
.

 

It is you, dear reader, who makes our lives of writing, coding, and teaching possible. So thank you for buying our book.

 
Index
Symbols
#import,
Testing your subclass
%@ prefix,
Format strings
.h files,
Creating an NSObject subclass
.m files,
Creating an NSObject subclass
,
Accessor methods
@ prefix
creating strings with,
Creating strings
and Objective-C keywords,
Creating an NSObject subclass
@autoreleasepool,
For the More Curious: Autorelease Pool and ARC History
@class,
Creating BNRItemStore
@end,
Creating an NSObject subclass
@implementation,
Accessor methods
@interface,
Creating an NSObject subclass
@optional,
Protocol methods
@private,
NSCopying
@property,
Declaring properties
@protected,
NSCopying
@protocol,
Protocols
@public,
NSCopying
@selector(),
UINavigationBar
@synthesize,
Synthesizing properties
^,
Declaring block variables
_cmd,
For The More Curious: Application State Transitions
__block,
For the More Curious: The __block Modifier, Abbreviated Syntax, and Memory
__bridge,
Creating and using keys
,
Core Foundation and toll-free bridging
__unsafe_unretained,
Strong and Weak References
__weak,
Strong and Weak References
A
accessor methods,
Accessor methods
(see also
properties
)
accessory indicator (UITableViewCell),
UITableViewCells
action methods,
Setting targets and actions
active state,
Application States and Transitions
actor objects,
The actor design pattern
addAnimation:forKey:,
Spinning with CABasicAnimation
addObject:,
Beginning RandomPossessions
,
NSArray and NSMutableArray
addSubview:,
Creating a Custom View
alloc,
Creating objects
,
Creating BNRItemStore
Allocations instrument,
Allocations Instrument
allocWithZone:,
Creating BNRItemStore
analyzing (code),
Static Analyzer
angled brackets,
Putting the pieces together
animation transactions,
Implicitly Animatable Properties
animationDidStop:finished:,
Animation completion
animations
(see also
CALayer
,
layers
)
and data types,
Animation Objects
keyframes in,
Animation Objects
timing functions of,
Timing functions
animationWithKeyPath:,
Spinning with CABasicAnimation
anonymous functions (see
blocks
)
anti-aliasing,
For the More Curious: Retina Display
API Reference,
Using the documentation
APIs
(see also
frameworks
)
App ID,
Deploying an Application
Apple documentation,
Using the documentation
application bundle,
Application Sandbox
,
For the More Curious: The Application Bundle
,
For the More Curious: NSBundle’s Role in Internationalization
application delegates,
Model-View-Controller
,
For the More Curious: The main Function and UIApplication
application dock,
Application States and Transitions
application domain,
Using NSUserDefaults
application sandbox,
Application Sandbox
,
For the More Curious: The Application Bundle
application states,
Application States and Transitions
,
For The More Curious: Application State Transitions
application:didFinishLaunchingWithOptions:,
Views and the View Hierarchy
,
For the More Curious: The main Function and UIApplication
applicationDidBecomeActive:,
For The More Curious: Application State Transitions
applicationDidEnterBackground:,
NSKeyedArchiver and NSKeyedUnarchiver
,
Application States and Transitions
,
For The More Curious: Application State Transitions
applications
(see also
debugging
,
universal applications
)
allowing orientations,
Forcing Landscape Mode
build settings for,
Build Settings
directories in,
Application Sandbox
entitlements of,
Ubiquity Containers
launch images for,
Launch Images
optimizing CPU usage,
Time Profiler Instrument
profiling,
Instruments
running on simulator,
Build and Run on the Simulator
user preferences in,
NSUserDefaults
applicationWillEnterForeground:,
For The More Curious: Application State Transitions
applicationWillResignActive:,
For The More Curious: Application State Transitions
ARC (Automatic Reference Counting)
(see also
memory management
)
and Core Foundation objects,
Core Foundation and toll-free bridging
and retain cycles,
Strong and Weak References
archiveRootObject:toFile:,
NSKeyedArchiver and NSKeyedUnarchiver
archiving
described,
Archiving
implementing,
Archiving
thumbnail images,
Image Manipulation
and XIB files,
Archiving
arguments,
Sending messages
arrays
copying,
NSCopying
vs. dictionaries,
NSDictionary
fast enumeration of,
Fast Enumeration
and memory management,
How objects lose owners
assistant editor,
An Additional UIViewController
,
Taking pictures and UIImagePickerController
atomic,
Declaring properties
attributes (Core Data),
The model file
,
NSManagedObject and subclasses
attributes inspector,
Building Interfaces
,
Interface Properties
auto-completion (in Xcode),
Implementing Methods
,
Code Snippet Library
,
Using the Store
automatic reference counting (see
ARC (Automatic Reference Counting)
)
autorelease,
For the More Curious: Autorelease Pool and ARC History
autorelease pool,
For the More Curious: Autorelease Pool and ARC History
autoresize masks,
Autorotation
,
Setting autoresizing masks programmatically and bitwise operations
autorotation,
Autorotation
,
Splitting Up Nerdfeed
availableMediaTypesForSourceType:,
For the More Curious: Recording Video
awakeFromFetch,
NSManagedObject and subclasses
awakeFromInsert,
NSManagedObject and subclasses
B
background state,
Application States and Transitions
,
For The More Curious: Application State Transitions
backgroundColor,
The drawRect: Method
becomeFirstResponder,
Motion Events
binary numbers,
Setting autoresizing masks programmatically and bitwise operations
bitmap contexts,
For the More Curious: Layers, Bitmaps, and Contexts
bitwise operators,
Setting autoresizing masks programmatically and bitwise operations
__block,
For the More Curious: The __block Modifier, Abbreviated Syntax, and Memory
blocks
and code-completion,
Using the Store
timing of execution,
Caching the RSS Feed
BNRConnection,
The actor design pattern
bounds,
The drawRect: Method
brackets,
Sending messages
,
Instance variables
,
Putting the pieces together
breakpoint navigator,
Stepping through code
breakpoints,
Using breakpoints
,
Stepping through code
__bridge,
Creating and using keys
,
Core Foundation and toll-free bridging
build configurations,
Build Settings
build phases,
For the More Curious: Build Phases, Compiler Errors, and Linker Errors
build settings,
Build Settings
bundles

Other books

King of Diamonds by Cheyenne McCray
Brett's Little Headaches by Silver, Jordan
The Christmas Carrolls by Barbara Metzger
The Complete Stories by Flannery O'Connor
The Girl in My Dreams by Logan Byrne
Yuletide Cowboy by Debra Clopton
Pandora Gets Lazy by Carolyn Hennesy
The Hollow City by Dan Wells


readsbookonline.com Copyright 2016 - 2024