Preparing Grocery Dude for Chapter 1 - Learning Core Data for iOS (2014)

Learning Core Data for iOS (2014)

A. Preparing Grocery Dude for Chapter 1

This appendix details the steps required to build the Grocery Dude sample application from scratch. Grocery Dude will be developed across the course of this book, and as each chapter introduces topics on Core Data, you’ll expand Grocery Dude to practice what you’ve learned. These instructions require at least Xcode 5 and iOS 7.

New Xcode Project

The creation of the base Xcode project isn’t related to Core Data, so the instructions to build it are tucked away in this appendix. If you prefer, you may skip the creation of this project and begin Chapter 1, “Your First Core Data Application.” A link to the Xcode project created as a result of this appendix is available in Chapter 1.

Create the initial Grocery Dude Xcode project as follows:

1. Open Xcode and click Create a new Xcode project.

2. Choose the iOS > Application > Single View Application template and click Next.

3. Set the project options shown in Figure A.1, substituting Tim Roadley with your own developer name, and then click Next.


Figure A.1 Project options

4. Select an appropriate directory for the new project, ensure Create git repository is not ticked, and then click Create.

Storyboard Design

The initial storyboard will be a simple configuration made up of a View Controller and Table View Controller embedded in a Navigation Controller.

Update Grocery Dude as follows to create the initial storyboard:

1. Select Main.storyboard, which is located in the Xcode Group called Grocery Dude.

2. Drag a Table View Controller from the Utilities pane onto the storyboard, placing it to the left of the existing View Controller. You can toggle the Utilities pane by pressing Option+image+0 together.

3. Ensure the new Table View Controller is selected.

4. Tick Is Initial View Controller, as shown in Figure A.2 at the bottom right. If you can’t see these settings, make sure the Utilities pane is open at the Attributes Inspector tab. You can do this by selecting View > Utilities > Show Attributes Inspector or by pressing Option+image+4together.


Figure A.2 Setting the initial View Controller

5. Ensure the Table View Controller is selected and then click Editor > Embed In > Navigation Controller.

6. Drag a Bar Button Item on to the top right of the Table View Controller.

7. Select the new Bar Button Item.

8. Change the Identifier to Add in the Bar Button Item section of Attributes Inspector, as shown in Figure A.3.


Figure A.3 Setting a Bar Button Item identifier

9. Hold down Control and drag a line from the Add button to the center of the View Controller, and select Action Segue > push.

10. Select the new action segue and then set its Identifier to Add Item Segue using the Attributes Inspector, as shown in Figure A.4.


Figure A.4 Add Item Segue

11. Set the Title of the Table View Controller to Items by double-clicking the title area.

12. Set the Title of the View Controller to Item by double-clicking the title area.

13. Select the Prototype Cell found in the Table View.

14. Set the Style of the Table View Cell to Basic and the Identifier to Item Cell using Attributes Inspector, as shown in Figure A.5.


Figure A.5 Item Cell

15. Arrange the storyboard as shown in Figure A.6.


Figure A.6 The initial storyboard

App Icons and Launch Images

Like any iOS app, Grocery Dude needs icons and images to make it look unique.

Update Grocery Dude as follows to configure the appropriate app icons:

1. Download and extract

2. Select Images.xcassets, which is an Asset Catalog that will contain the application images.

3. Select AppIcon.

4. Drag AppIcon_29pt.png into the iPhone 29pt placeholder.

5. Drag AppIcon_40pt.png into the iPhone Spotlight 40pt placeholder.

6. Drag AppIcon_60pt.png into the iPhone App 60pt placeholder.

Figure A.7 shows the expected results.


Figure A.7 App icons

Update Grocery Dude as follows to configure the appropriate launch images:

1. Ensure Images.xcassets is still selected.

2. Select LaunchImage.

3. Drag LaunchImage_2x.png into the iPhone Portrait - 2x placeholder.

4. Drag LaunchImage_R4.png into the iPhone Portrait - R4 placeholder.

Figure A.8 shows the expected results.


Figure A.8 Launch images

The sample project is now ready for Chapter 1. Feel free to run Grocery Dude on the iOS Simulator or an iOS device to examine your handiwork so far! Note that the deployment target is iOS 7 and previous versions of iOS aren’t supported with Grocery Dude.