Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3943302
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:45:58+00:00 2026-05-20T00:45:58+00:00

This is a sample from book Cocoa Programming For Mac Os X 3rd(HD) chapter

  • 0

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)windowControllerDidLoadNib:(NSWindowController *) 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 ^_^

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:45:58+00:00Added an answer on May 20, 2026 at 12:45 am

    That seems like a very reasonable response… you added NSData to your array named employees; guessing from the names, and from the KVC, you probably meant to add p1 to your array instead. So, try:

    [employees addObject:p1];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is sample program from Beginning Linux Programming book: #include <stdio.h> #include <term.h> #include
So I started reading this book: http://www.amazon.com/Cocoa-Design-Patterns-Erik-Buck/dp/0321535022 On chapter 2 it explains about the
This is from some sample code from a book // On launch, create a
I have this sample text, which is retrieved from the class name on an
In the below code sample, what does {0:X2} mean? This is from the reflection
Following sample is taken from Dive into python book. class MP3FileInfo(FileInfo): store ID3v1.0 MP3
I'm studying Enterprise Patterns and I'm reading this book . I just read chapter
This is pretty simple, I come from a swing/awt background. I'm just wondering what
I have a simple query like this: select * from mytable where id >
I have very simple select like this: SELECT * FROM table WHERE column1 IN

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.