Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Mac OS X Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-12-2011, 02:55 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 5
supersurabbit is on a distinguished road
Default NSMutableArray KVC/KVO question.......

This is a sample from book "Cocoa Programming For Mac Os X 3rd(HD)" chapter 7 "Key-Value Coding. Key-Vaule Observing

Here is the code:

Person.h:

#import <Foundation/Foundation.h>


@interface Person : NSObject {
NSString *personName;
float expectedRaise;
}
@property (readwrite, copy) NSString *personName;
@property (readwrite) float expectedRaise;

@end

Person.mm:

#import "Person.h"
@implementation Person

@synthesize expectedRaise;
@synthesize personName;

- (id)init
{
[super init];
expectedRaise = 0.05;
personName = @"New Person";
return self;
}

- (void)dealloc
{
[personName release];
[super dealloc];
}

@end

MyDocument.h:

#import <Cocoa/Cocoa.h>

@interface MyDocument : NSDocument
{
NSMutableArray *employees;
}

@property (retain) NSMutableArray *employees;

@end

MyDocument.mm:

#import "MyDocument.h"
#import "Person.h"

@implementation MyDocument

@synthesize employees;

- (id)init
{
if (![super init])
return nil;

employees = [[NSMutableArray alloc] init];

return self;
}
- (void)dealloc
{
[employees release];
[super dealloc];
}

- (void)windowControllerDidLoadNibNSWindowControll er *) aController


@end

And the sample works fine.(A blank table at first and you can add or delete record).

Now I tried to add some records to the array so that the blank table would have
someting in it at first.

Here's what I'v tried(inside the init method):

[self willChangeValueForKey:@"employees"];
Person *p1 = [[Person alloc] init];
[employees addObject: [NSData dataWithBytes: &p1 length: sizeof(p1)]];
[self didChangeValueForKey:@"employees"];

But when I build and wrong I got the error msg:

[<NSConcreteData 0x422bf0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key personName.
......

Can any one help me out of here? Thanks in advance ^_^
supersurabbit is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 372
8 members and 364 guests
husthlj, illogical, LegionMD, LunarMoon, mer10, Murphy, padsoftware, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,677
Threads: 94,127
Posts: 402,916
Top Poster: BrianSlick (7,990)
Welcome to our newest member, husthlj
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:12 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0