Database Reference
In-Depth Information
Storyboard Modifications
The final thing we need to do is to set up our Storyboard to interact with these class files.
Select the
UITableViewController
in the Storyboard and set its class to
CloseFriendsTableViewController
.
1.
Ctrl-drag from the Add Button to the
TableViewController
and select
btnAddPressed:
from the pop-up.
2.
Select the
UIViewController
in the Storyboard and set its class to
CloseFriendDetailViewController
.
3.
In the Connections Inspector, drag a connection for
imgFriend
,
txtBirthday
,
txtFirstName
, and
txtLastName
to the appropriate object in the view.
4.
5.
Next, Ctrl-drag from each of the text fields to the
CloseFriendDetailViewController
object and select delegate underneath
Outlets in the popup.
Go ahead and build and run the app. You should be able to add new Close Friends and delete them
if you wish. You can select an image in the Detail view and it will show up in that view. All this data is
being saved locally. Now I will show you how quick and easy it is to integrate iCloud with Core Data.
Adding iCloud to Core Data
Because we are going to add iCloud support we need to tell our persistent store that it will
be iCloud enabled. We do this is by creating an
NSDictionary
with optional parameters and
passing that to the
addPersistentStoreWithType:configuration:URL:options:error
method.
We do this in our Application Delegate, which is where all our Core Data Stack code is. Find the
persistentStoreCoordinator
method in
CTAppDelegate.m
and change it to this:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:
@"iCloudTestApp.sqlite"];
NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:
[self managedObjectModel]];
NSDictionary *options = @{NSPersistentStoreUbiquitousContentNameKey:@"Store"};
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil
URL:storeURL options:options error:&error]) {
Search WWH ::
Custom Search