Chapter-11: Storing Information

This forum contains all the assignments and questions readers may have for each chapter.

Moderator: gary.bennett

Chapter-11: Storing Information

Postby gary.bennett » Sat Aug 14, 2010 3:45 pm

Topics Covered:
    Understanding Memory
    Bits, Bytes, and Bases
    Understanding Memory Address Basics
    Requesting Memory
    Working with Automatic Variables and Pointers
    Deallocating Memory
    Using Special Pointers
    Managing Memory in Objective-C.
    Using the Retain/Release Model
    Working with Implied Retain Messages.
    Sending the dealloc Message
    If Things Go Wrong
Attachments
Ch11 - CoreData.zip
Chapter 11 Source Code
(83.64 KiB) Downloaded 332 times
User avatar
gary.bennett
 
Posts: 564
Joined: Thu Feb 26, 2009 3:12 pm

Re: Chapter-11: Storing Information

Postby Zorro » Mon Jan 23, 2012 1:16 pm

Why doesn't this chapter show us how to accomplish storing information on the iPhone. Quite frankly, things are quite different with iOS and this chapter totally missed the mark for the wanna-be iPhone programmer. It would at least be nice to have some kind of input in this forum of how to accomplish the equivalent exercise on the iPhone, not just on the Mac.... my two-cents worth!
Zorro
 
Posts: 0
Joined: Tue Dec 06, 2011 7:39 pm

Re: Chapter-11: Storing Information

Postby gary.bennett » Fri Mar 02, 2012 10:05 am

A common errata question:

I dont have a Book class and I don't get a bind to Book Store Core Data App... option only App Delegate,Application,File's Owner, Font Manager and Shared User Defaults Controller.
what am I doing wrong?

The version of Xcode i'm using is 4.2 (latest version) could this be a problem as I have had to find work arounds for other exercises?

Warm Regards

Paul

PS your book is great I have just purchased iPhone cool projects and considering joining your online lessons.
User avatar
gary.bennett
 
Posts: 564
Joined: Thu Feb 26, 2009 3:12 pm

Re: Chapter-11: Storing Information

Postby gary.bennett » Fri Mar 02, 2012 10:06 am

gary.bennett wrote:A common errata question:

I dont have a Book class and I don't get a bind to Book Store Core Data App... option only App Delegate,Application,File's Owner, Font Manager and Shared User Defaults Controller.
what am I doing wrong?

The version of Xcode i'm using is 4.2 (latest version) could this be a problem as I have had to find work arounds for other exercises?

Warm Regards

Paul

PS your book is great I have just purchased iPhone cool projects and considering joining your online lessons.


Here is the answer:

Code: Select all
1.  Apple did change the result of the create managed object.

It now shows

//
//  Author.h
//  BookStoreTest
//
//  Created by Natalie Lees on 3/2/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>


@interface Author : NSManagedObject

@property (nonatomic, retain) NSString * lastname;
@property (nonatomic, retain) NSString * firstname;
@property (nonatomic, retain) NSManagedObject *books;

@end


2.  If you go to view -> Utilities->Show Identity Inspector, you can change the Label.

3.  Select app delegate from the Drop down.  Apple removed the Application name in front of the app delegate.

4.  Once the app delegate is selected, you will be able to write managedObjectContext.

Hopefully that makes sense and answers the questions.

Thanks

Brad
User avatar
gary.bennett
 
Posts: 564
Joined: Thu Feb 26, 2009 3:12 pm

Re: Chapter-11: Storing Information

Postby johnyrox » Sun Mar 04, 2012 4:50 pm

Hi Brad
Thanks for the reply, I have followed your instructions and the book and author files appear as they should, however there must be a lot of changes in the versions i.e. to connect BookArray (the array controller) to the table view I cant control - drag, I can only left click to display the options from there I can only choose Referencing outlets - New Referencing Outlets - dataSource or delegate. Which option should be selected? the options for the Add and Delete Buttons are different too. I think this chapter is to important to skip so I'm trying to work through it.

Regards
Paul
johnyrox
 
Posts: 0
Joined: Sat Feb 04, 2012 12:43 am

Re: Chapter-11: Storing Information

Postby joseph.toronto » Mon Aug 06, 2012 8:45 pm

So I decided to play around a little with core-data, and it snowballed into playing with a while bunch of other things as well. I'm making a practice app that will allow me to build a "garage" of cars. Mind you this is in Cocoa and not Cocoa Touch. It's just a simple, silly database. Right now I have my simple model done in core-data (just one entity called "cars" and some suitable attributes), I have the main view all linked up, but where hit a brick wall is making the "add view" window link up with everything else.

In the main window, I have a NSTableview, some text labels, and an imagewell for displaying all the data. When the user clicks the "add" button, instead of linking to the "add" function of the array controller, an "Add" window pops up with text fields, an imagewell, and a "save" button. I also have an AddVewController with all the outlets defined as instance variables. Here's where I'm stuck.

I want the user to be able to fill out the text-fields and drop an image in the imagewell, and then when they press "save", it adds it to the core-data model. Do I create a method in the AddViewController that passes the values into an array when the user presses save? If so, what do I do with that array? Should I just use Cocoa-bindings and Key-Value Coding? Am I supposed to involve a delegate of some sort at this point?

This is probably simpler than I think it is but after hours of researching online I'm getting overwhelmed with information and none of it is jumping up and down and pointing right now.

Thanks!
joseph.toronto
 
Posts: 4
Joined: Sat Jun 23, 2012 12:29 pm

Re: Chapter-11: Storing Information

Postby joseph.toronto » Tue Aug 21, 2012 9:34 pm

Even better now. I decided to start smaller and just work off the book's BookStore app and build from there. I re-created the project as shown on the book, but saving and undo functions aren't working. This is in XCode 4.4. It seemed to work fine in 4.3 when I tried it a month or so ago. Did something change with XCode 4.4? When running the app, save and undo are grayed out as well.
joseph.toronto
 
Posts: 4
Joined: Sat Jun 23, 2012 12:29 pm

Re: Chapter-11: Storing Information

Postby RavingMonkey » Thu Oct 18, 2012 9:26 am

Guys,

I am working through the book, and although new to Obj-C and xCode, I am getting to grips with it, however following the Core Data tutorial I have hit a major stumbling block.

I get as far as dragging an "Array Controller" to the storyboard, but in the version of xCode I have (the latest) I am not able to see this option available in the Objects Library, I assume there is a delta between the book and the current version of xCode, but where/how do I do this now. I also downloaded the source code last night, opened in xCode and xCode is saying there is an error in the code.

Anyone else hit this, anyone know how I can progress? Managing Data is key for me moving forward.

Does anyone else have a good example of using Core Data that walks you through like this book does?

Thanks

Mike
RavingMonkey
 
Posts: 0
Joined: Wed Oct 17, 2012 4:06 am

Re: Chapter-11: Storing Information

Postby Magical1 » Sat Oct 27, 2012 11:48 am

I am using Xcode 4.5.1 and I have got to the step 3 on page 254 in Managed Object Context ->Setting Up the Interface

When I double click on the Array Controller in the Objects panel on the left of the Editor nothing happens.

Is there another way to associate the BookArray with the Array Controller?

Thanks,
Michael
Magical1
 
Posts: 0
Joined: Sun Oct 21, 2012 1:18 am

Re: Chapter-11: Storing Information

Postby Titas22 » Thu May 02, 2013 11:32 am

Hi. I'm getting an error: "Unacceptable type of value for attribute: property = "price"; desired type = NSNumber; given type = __NSCFString;" when I change price to something, but it is okay if i leave it 0.0. Even though after closing and reopening app it is blank (nothing saved) :( I am using the newest xcode :)
Titas22
 
Posts: 0
Joined: Thu May 02, 2013 3:37 am

Re: Chapter-11: Storing Information

Postby gary.bennett » Thu May 02, 2013 1:26 pm

Titas22 wrote:Hi. I'm getting an error: "Unacceptable type of value for attribute: property = "price"; desired type = NSNumber; given type = __NSCFString;" when I change price to something, but it is okay if i leave it 0.0. Even though after closing and reopening app it is blank (nothing saved) :( I am using the newest xcode :)


HI Titas, If you send me your code I will look at it.
Send to: gary At xcelMe dot com
User avatar
gary.bennett
 
Posts: 564
Joined: Thu Feb 26, 2009 3:12 pm

Re: Chapter-11: Storing Information

Postby alexvarey » Sun Mar 30, 2014 1:31 am

Hi,

I'm working my way through this excellent book and have a problem when trying to run the core data bookstore. I'm using xcode 5 and the error message I get is:
[<NSTableView 0x1002495c0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key price.
This is the same with my version of the project, or the downloaded zip file. I'm guessing it's something to do with the new xcode?? Any help would be really appreciated.

Many thanks,

Alex
alexvarey
 
Posts: 0
Joined: Sat Mar 29, 2014 5:58 am


Return to Book -> Objective-C for Absolute Beginners: (2nd Edition) iPhone and Mac Programming Made Easy

cron