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

  • Home
  • SEARCH
  • 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 7521773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:19:31+00:00 2026-05-30T02:19:31+00:00

I’m getting the following error: this class is not key value coding-compliant for the

  • 0

I’m getting the following error:

“this class is not key value coding-compliant for the key temp_f”

my AppDelegate class files:

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate> {
    IBOutlet NSTableView *tableView;
    NSArray *current;
}

@property (assign) IBOutlet NSWindow *window;
@end

#import "AppDelegate.h"
#import "CurrentWeather.h"
#import "XMLCurrent.h"

@implementation AppDelegate

@synthesize window = _window;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    XMLCurrent *currentXML = [[XMLCurrent alloc] init];
    NSError *error = nil;

    current = [currentXML fetchCurrentWithError:&error];
    [tableView reloadData];
}

- (NSInteger)numberOfRowsInTableView:(NSTableView *)theTableView {
    return [current count];
}

- (id)tableView:(NSTableView *)theTableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
    CurrentWeather *c = [current objectAtIndex:row];
    return [c valueForKey:[tableColumn identifier]];
}
@end

my CurrentWeather class files:

#import <Foundation/Foundation.h>

@interface CurrentWeather : NSObject {
    NSString *location;
    NSString *weather;
    NSString *degreesF;
}

@property (nonatomic, copy) NSString *location;
@property (nonatomic, copy) NSString *weather;
@property (nonatomic, copy) NSString *degreesF;

@end

#import "CurrentWeather.h"

@implementation CurrentWeather

@synthesize location, weather, degreesF;

@end

my XMLCurrent class files:

#import <Foundation/Foundation.h>

@interface XMLCurrent : NSObject <NSXMLParserDelegate> {
    NSMutableArray *current;
    NSMutableString *currentString;
    NSMutableDictionary *currentFields;
}

- (NSArray *)fetchCurrentWithError:(NSError **)outError;

@end

#import "XMLCurrent.h"
#import "CurrentWeather.h"

@implementation XMLCurrent

- (id)init {
    self = [super init];

    if (self) {
        current = [[NSMutableArray alloc] init];
    }
    return self;
}

- (NSArray *)fetchCurrentWithError:(NSError **)outError {
    BOOL success;

    NSURL *xmlURL = [NSURL URLWithString:@"http://www.weather.gov/xml/current_obs/KCLT.xml"];

    NSURLRequest *req = [NSURLRequest requestWithURL:xmlURL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30];

    NSURLResponse *resp = nil;

    NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&resp error:outError];
    if (!data) {
        return nil;
    }

    [current removeAllObjects];

    NSXMLParser *parser;
    parser = [[NSXMLParser alloc] initWithData:data];
    [parser setDelegate:self];

    success = [parser parse];
    if (!success) {
        *outError = [parser parserError];
        return nil;
    }

    NSArray *output = [current copy];
    return output;
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI 
 qualifiedName:(NSString *)qName 
    attributes:(NSDictionary *)attributeDict {

    if ([elementName isEqual:@"current_observation"]) {
        currentFields = [[NSMutableDictionary alloc] init];
    }
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI 
 qualifiedName:(NSString *)qName {

    if ([elementName isEqual:@"current_observation"]) {
        CurrentWeather *currentCond = [[CurrentWeather alloc] init];
        [currentCond setLocation:[currentFields objectForKey:@"location"]];
        [currentCond setWeather:[currentFields objectForKey:@"weather"]];
        [currentCond setDegreesF:[currentFields objectForKey:@"temp_f"]];

        [current addObject:currentCond];
        currentCond = nil;
        currentFields = nil;
    } else if (currentFields && currentString) {
        NSString *trimmed;
        trimmed = [currentString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        [currentFields setObject:trimmed forKey:elementName];
    }
    currentString = nil;
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
    if (!currentString) {
        currentString = [[NSMutableString alloc] init];
    }
    [currentString appendString:string];
}
@end

The keys are used as the “identifier” in a table view. For some reason, if the key has an underscore in it (such as temp_f) I get an error. The underscore is necessary because it is the name of the element in the XML file. If there is no underscore, then no error. How can I get data from an XML element that contains an underscore?

The xml data is being parsed from http://www.weather.gov/xml/current_obs/KCLT.xml

  • 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-30T02:19:33+00:00Added an answer on May 30, 2026 at 2:19 am

    CurrentWeather has a degreesF property, which you set from the temp_f XML field. You need to set the identifier for the table column to “degreesF” not “temp_f”. This has nothing to do with temp_f containing an underscore. Rather, the problem is that CurrentWeather isn’t Key Value Coding compliant for the key “temp_f” (just as the error states) because it doesn’t have a property named “temp_f”.

    Explaining in further detail, in your -tableView:objectValueForTableColumn: method, you use the column’s identifier as a key into a CurrentWeather instance. Since the identifier is “temp_f”, you’re doing this: [c valueForKey:@"temp_f"]. That throws an exception because CurrentWeather doesn’t have a temp_f property.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to

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.