Challenge 2 Help Needed


#1

I have been trying to work through challenge 2 and I have been having problems.

In the code to be entered into the RMDocument.m

In the -(id) init code

-(id) init
{
self = [super init];
if (self) {
employees = [NSMutableArray array];
}
return self;
}
Should the line in bold above actually be:
employees = [NSMutableArray alloc] init];

and,
I get an error on this line.
[person setValue:anObject forKey:identifier];

The error is Receiver type ‘Person’ for instance message does not declare a method with selector ‘setValue forKey’

I have left the person class exactly the same as the Chapter 8 code.

Not sure about setting the identifiers the the name of the variable.

Stuck… Please help.


#2

Found a solution to the one part of my problem… A typo !

I retyped the line I was having trouble with and discovered this…

[person setValue:anObject forkey:identifier];
[person setValue:anObject forKey:identifier];

the forKey was all lower case forkey .
So the issue with the error is resolved, but I am still not sure how to link everything together.


#3

Hello,

The two lines:

employees = [NSMutableArray array]; // and: employees = [[NSMutableArray alloc] init];

are effectively equivalent, under ARC. +[NSMutableArray array] returns a retain-autoreleased object, and the alloc-init version returns a retained object, but since ARC is handling the reference counting for you there is no real difference.

What problem are you still having, exactly?

Adam


#4

I was having difficulty with "you will set the identifier of each column to the name of the variable that you would like displayed"
I eventually found the “identifier” text field inside of the identity inspector for the TableView Column that I was applying the variable to.


#5

Thank you. I was having problem finding the identifier too. The book says it’s found in “Attributes Inspector”, but as you pointed out, it’s really in the “Identity Inspector”.


#6

I too had this difficulty. The program seemed to be working apart from the lack of the ability to edit the ‘New Person’ and ‘5%’ values as a new employee was added. Now that I have added ‘personName’ as the ‘User Interface Item Identifier’ in the Identity Inspector form for the ‘Name’ NSTableColumn and ‘expectedRaise’ ditto for the ‘Raise’ NSTableColumn, I find that when edit either value (of any employee) and press the ‘Enter’ key or click away from the entered text, my program crashes e.g.

2012-01-02 20:52:20.350 RaiseManual[4725:707] Exception detected while handling key input.
2012-01-02 20:52:20.351 RaiseManual[4725:707] [<Person 0x10060d220> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key _NS:21.

and I’m baffled. I presume also that we’re meant to continue onto Chapter 9 with the solution that uses an NSArrayController and bindings, and not our result for Chapter 8’s Challenge 2?


#7

JohnUK,

Try putting a breakpoint in tableView:setObjectValue:forTableColumn:row: and double check the value of identifier. This method is called when you end editing a cell in the table view.

Also, yes, you will need to go back to your pre-Challenge exercise-in-progress when proceeding with Chapter 9.

Adam


#8

[quote=“AdamPreble”]JohnUK,

Try putting a breakpoint in tableView:setObjectValue:forTableColumn:row: and double check the value of identifier. This method is called when you end editing a cell in the table view.

Also, yes, you will need to go back to your pre-Challenge exercise-in-progress when proceeding with Chapter 9.

Adam[/quote]

I’d written “NSString *identifier = [aTableView identifier];” instead of the correct “NSString *identifier = [aTableColumn identifier];”.

The moral of this - and similar mistakes - is, I think, that if you can’t spot a typo in code you’ve transcribed (or written) after several readings, then take time out and come back refreshed. It’s an old lesson - I’m an experienced programmer with other technologies - but one I have to learn over and over again. :slight_smile:

Thanks for your suggestion, Adam, and thanks to the others who realised that the Identity Inspector was required.