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 7976645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:57:50+00:00 2026-06-04T08:57:50+00:00

I am time implementing the key value coding in my program so i am

  • 0

I am time implementing the key value coding in my program so i am not much comfortable with it . I am having the controller class in which the parsing methods are implemented in start document i have initialize the object and keys. All data members of class Universal are type id.

            univ=[[Universal alloc] init];
            [univ setValue:univ.datamember1 forKey:@"1"];
            [univ setValue:univ.datamember2 forKey:@"2"];
            [univ setValue:univ.datamember3 forKey:@"3"];
            [univ setValue:univ.datamember4 forKey:@"4"];
            [univ setValue:univ.datamember5 forKey:@"5"];

I am setting the value on data member in end element method :

         id temp1=[univ valueForKey:@"1"];
        temp1=strVal;
        [resultArray addObject:univ];

and i am getting the following exception for this code:

'NSUnknownKeyException', reason: '[<Universal 0x6e994d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key 1

what is the reason for this. Is there missing something or everything gone wrong??

  • 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-06-04T08:57:52+00:00Added an answer on June 4, 2026 at 8:57 am

    For the most part, you don’t have to implement Key-Value Coding. Instead, you create your classes to comply with various conventions and then Key-Value Coding works for it automatically.

    The conventions are about how you name methods in order to make a property accessible via KVC.

    Your code:

            univ=[[Universal alloc] init];
            [univ setValue:univ.datamember1 forKey:@"1"];
            [univ setValue:univ.datamember2 forKey:@"2"];
            [univ setValue:univ.datamember3 forKey:@"3"];
            [univ setValue:univ.datamember4 forKey:@"4"];
            [univ setValue:univ.datamember5 forKey:@"5"];
    

    is strange. What are you trying to do here? This code looks like it’s trying to set properties on the univ object from other properties of the univ object. That would be redundant.

    I suspect you think that you’re establishing synonyms or aliases here – that you’re making key “1” map to the property datamember1. That’s not correct. The -setValue:forKey: method is for actually setting a property’s value. It’s very much like calling a setter method; in fact, it usually does result in calling a setter method.

    So, what you’ve written is very much like the following:

            univ=[[Universal alloc] init];
            [univ set1:univ.datamember1];
            [univ set2:univ.datamember2];
            [univ set3:univ.datamember3];
            [univ set4:univ.datamember4];
            [univ set5:univ.datamember5];
    

    I doubt that’s anything that you meant to do. It might help you to explain what you’re trying to do in non-KVC terms. What properties are you trying change (if you are)? What values would you like to assign to them? How would you do that using just ordinary setters and getters?

    Later, you posted this code:

        id temp1=[univ valueForKey:@"1"];
        temp1=strVal;
        [resultArray addObject:univ];
    

    Again, this is strange and confusing. I suspect you’re trying to change a property value on univ, but that’s not what that code accomplishes, even if it could be made to work. The first line attempts to get the value of a property of the univ object, where the property’s name is “1”. That’s not a valid name for a property. Anyway, it stores the retrieved value into a local variable temp1. The second line simply throws away the result of the first line and stores a different value into the local temp1 variable. The temp1 variable is independent of the univ object, even though a moment ago it was storing a result retrieved from the univ object. Changing temp1 can’t change univ (although messaging the object pointed to by temp1 could change that object and it might also be pointed to by univ).

    It seems to me that you aren’t yet ready to be using Key-Value Coding. You need a better understanding of the basics. Also, it’s almost never necessary to use Key-Value Coding with a static, known-at-compile-time key. Key-Value Coding is for dynamic access to properties of an object when you don’t know the name of that property at compile time but you’ll have the name as data at run time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam having a fun time with implementing SHA1 and HMAC methods in a iPhone
Using the Qt DBus library, I'm having a hard time registering an object implementing
i am implementing dictionary in which key is a string keyword.suppose i have following
I am implementing a system where I need real-time updates. I have been looking
I'm implementing a stack application, however every time I push an item onto the
I am implementing a session manager for my application. Each time an activity is
I'm new to database design and I considering implementing something that will be time
This is my first time implementing In App Purchases. During development and testing of
I'm having a tough time trying to implement a slideToggle event and at the
CREATE TABLE item ( link MEDIUMINT UNSIGNED PRIMARY KEY NOT NULL, title TEXT NOT

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.