Reputation: 5424
I'm trying to make a XML-parser that saves data from YR.no-API. The parser should add data to these two datastructures. My problem is when i try to add a WeatherTimeData object to my array in WeatherData, it seems like the objects doesnt get added, the following count always give me zero
- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementname isEqualToString:@"time"])
{
[self.weatherdata.timedata addObject:currentWeatherTimeData];
NSLog(@"amount of objects in timedata-array %d", [[self.weatherdata timedata] count]);
}
These are my two data-structures, i alloc weatherData in the following method
-(id) loadXMLByURL:(NSString *)urlString
{
_weatherdata = [[WeatherData alloc] init];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
parser = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
[parser parse];
return self;
}
Do i have to alloc the array inside of the weatherdata object?
WeatherData.h
@interface WeatherData : NSObject
@property (strong, nonatomic)NSString *town;
@property (strong, nonatomic)NSString *country;
@property (strong, nonatomic)NSMutableArray *timedata;
@end
WeatherData.m
@implementation WeatherData
@synthesize town = _town;
@synthesize country = _country;
@synthesize timedata = _timedata;
@end
WeatherTimeData.h
@interface WeatherTimeData : NSObject
@property (strong, nonatomic)NSDate *startTime;
@property (strong, nonatomic)NSDate *endTime;
@property (strong, nonatomic)NSString *iconSymbol;
@property (strong, nonatomic)NSString *windDirection;
@property (strong, nonatomic)NSString *windSpeed;
@property (strong, nonatomic)NSString *temprature;
@property (strong, nonatomic)NSString *preassure;
@end
WeatherTimeData.m
@implementation WeatherTimeData
@synthesize startTime = _startTime;
@synthesize endTime = _endTime;
@synthesize iconSymbol = _iconSymbol;
@synthesize windDirection = _windDirection;
@synthesize windSpeed = _windSPeed;
@synthesize temprature = _temprature;
@synthesize preassure = _preassure;
@end
Upvotes: 1
Views: 139
Reputation: 122401
This type of problem is classically because the object hasn't been allocated, and given Objective-C allows messages to be sent to nil
the programmer doesn't notice.
I think it would be nice to be able to provide a runtime environment variable where such events are logged to stdout...
I would suspect that [WeatherTimeData init]
isn't creating timedata
and that's because you haven't provided an implementation for it; just using @sythensize
isn't enough to create the objects.
Upvotes: 1