DPS923 MAP523 Lab 4

Begin working with the Core Data framework. Begin working with a navigation-based app.

.

DPS923 MAP523 Lab 4 – due Sunday, February 23, at 11:00pm

Due date: Sunday, February 23, at 11:00pm ET

Grade value: 4% of your final course grade

.

Objective(s)

Work with the Core Data framework

Work with a navigation based app

.

Introduction to the problem that you will solve

We need a simple app that will store data about Canadian provinces and cities.

The data will be created programmatically, when the app is launched for the first time on a device.

The app will feature two levels of navigation – a top-level list, and then navigation to a detail view. You can decide whether to display a list of provinces, or a list of cities – the choice is yours.

Here’s an example of an app that displays a list of provinces, with a drill-down to a detail view of that province’s data:

list-province . view-province

Here’s an example of an app that displays a list of cities, with a drill-down to a detail view of that city’s data:

city-list . city-view

Enjoy!

.

Specifications

Use the ClassesV2 as the ‘template’ for your app. Follow the procedure to rename your app to Core Data Intro.

Next, you will perform these tasks:

  1. Design the Province and City entities
  2. Generate custom classes for the entities
  3. Write code in the store initializer to create startup data for the app
  4. Decide whether you will display a list of provinces, or cities
  5. Create a fetched results controller for your chosen collection
  6. Iteratively code the controllers and views to complete the app’s functionality…
  7. Create a controller for the list view
  8. Create a controller for the detail view
  9. Design the storyboard scenes/views

.

Design the Province and City entities

Using the Core Data model editor, add Province and City entities. Note the naming convention: Entity names are singular.

Province gets this configuration:

entity-province

City gets this configuration:

entity-city

Very important:

For the “province” relationship, un-check (clear) the “Optional” check box in the Data Model Inspector. In other words, when you create a City object, you MUST have a reference to an existing Province object.

For the “cities” relationship, its relationship type must be “To Many”.

.

Generate custom classes for the entities

Select/highlight both entities. Then, on the Editor menu, choose “Create NSManagedObject Subclass…”. After you finish the procedure, you will have custom classes for your entities:

entity-custom-classes

Before continuing, add ‘import’ statements to the Model.h interface for both custom classes.

.

Write code in the store initializer to create startup data for the app

In the store initializer, write code to create three (3) Province objects. You can get descriptive data from Wikipedia.

Then, for one of the provinces, write code to create three (3) City objects. Again, you can get descriptive data from Wikipedia.

Remember to save your changes.

The store initializer will run during the init method of the model object initialization.

At this point, you can probably build and run your app. It will load with an empty list, but the data will get created.

.

Decide whether you will display a list of provinces, or cities

As noted earlier, you can decide whether to display a list of provinces or cities. It’s your decision.

.

Create a fetched results controller for your chosen collection

In the Model class, create an NSFetchedResultsController property for your chosen entity. As you expect, you will write a @property statement in the .h interface.

In the .m implementation, you will write a custom getter for the property. You can copy-paste the existing “frc_entity” code block, or edit code block.

FYI – If you copy-paste a new code block (instead of editing), your project will continue to build without errors.

.

Iteratively code the controllers and views to complete the app’s functionality

You will have to do the next three tasks (controllers for the list and detail views, and storyboard scenes) iteratively. You’ll have to switch among the code assets. There’s no straight-line way to do this work. 

.

Create a controller for the list view

Create a controller for the list view. It will be a subclass of UITableViewController, and its name will be <something>List – either ProvinceList, or CityList.

Make sure it adopts the NSFetchedResultsControllerDelegate protocol.

Use the coding patterns and techniques in the existing “EntityList” class to guide you.

In the app delegate, modify the code to recognize your new controller.

.

Create a controller for the detail view

Create a controller for the detail view. It will be a subclass of UIViewController, and its name will be <something>View – either ProvinceView or CityView.

Use the coding patterns and techniques in the existing “EntityView” class to guide you.

.

Design the storyboard scenes/views

Either replace or edit the existing scenes on the storyboard. If you edit:

  1. On the Connections Inspector, remove existing connections
  2. Change each scene’s “Custom Class” on the Identity Inspector
  3. Change the visible title of the “…List” scene
  4. Change the name of the segue’s identifier to better match your entity
  5. On the “…View” scene, replace the existing user interface objects with your own

.

How to display the list of cities on the province view scene

view-provinceIf you are working with ProvinceList and ProvinceView…

You noticed (above) that the province view scene includes a list of cities.

How was that done?

Well, think about the Province object that is passed to the ProvinceView controller.

It has a “cities” property.

What’s the data type of “cities”? It is an NSSet (a collection) of City objects!

Therefore, all you need to do is go through the collection, and extract the data you want. Here’s the pseudocode:

  1. Create an NSMutableString that will hold the string as it gets built
  2. Use the “for in” control structure to go through the “cities” collection
  3. For each item, appendString with the info that you want to display
  4. When you’re finished with the collection, set the property (use the description method to dump the string from the NSMutableString object

.

How to display province info on the city view scene

city-viewIf you are working with CityList and CityView…

You noticed (above) that the city view scene includes some province information.

How was that done?

Well, think about the City object that is passed to the CityView controller.

It has a “province” property.

What’s the data type of “province”? It is a Province object!

Therefore, all you need to do is extract the data you want.

.

.

.

.

.

Submitting your work

Follow these instructions to send me your work:

  1. Make sure your project works correctly
  2. Locate your Core Data Intro project folder in Finder
  3. Right-click the folder, and choose Compress “Core Data Intro”, which creates a zip file (make sure the zip file is fairly small, around 500KB or less)
  4. Login to My.Seneca, and in this course’s Assignments area, look for the upload link, and submit your work there

.

.

.

.

.

.

.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: