views:

53

answers:

1

Hi

I have a class DataObject as

Header :::

#import <Foundation/Foundation.h>


@interface DataObject : NSObject {
    NSString *erorrMessage;
    BOOL hasError;
    NSDictionary *dataValues;
}

@property(nonatomic, retain)NSString *erorrMessage;

@property(nonatomic)BOOL hasError;

@property(nonatomic, retain)NSDictionary *dataValues;

@end

Class Implementation::::

    #import "DataObject.h"

    @implementation DataObject

    @synthesize erorrMessage;
    @synthesize hasError;
    @synthesize dataValues;

    @end

And I have another class as DataManager

Header as ::::

#import <Foundation/Foundation.h>

@interface DataManager : NSObject 

- (DataObject *)getData :(NSString*)url;

@end

Implementation ::::

#import "DataManager.h"
#import "DataObject.h"
#import "JSON.h"


@implementation DataManager

- (DataObject *)getData :(NSString*)url{

    DataObject* dataObject = [[DataObject alloc]init];

    NSString *urlString = [NSString stringWithFormat:url];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
        //TODO: Here we have to check the internet connection before requesting.    
    NSError * erorrOnRequesting;
    NSData       *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&erorrOnRequesting];
    NSString* responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    if( erorrOnRequesting != nil)
    {
        dataObject.hasError = YES;
        dataObject.erorrMessage = @"Error on requsting to the web server";
        return dataObject;
    }

    NSError *errorOnParsing;
    SBJSON *json = [[SBJSON new] autorelease];
    NSDictionary *dataValues = [json objectWithString:responseString error:&errorOnParsing];
    [responseString release];   

    if(errorOnParsing != nil)
    {
        //TODO: We have to send the website a feedback that there is some problem on the server end.
        dataObject.hasError = YES;
        dataObject.erorrMessage = @"Error on parsing, the server returned invalid data.";
        return dataObject;
    }

    dataObject.hasError = NO;
    dataObject.dataValues = dataValues;

    return dataObject;
}

@end

Now when I build I got an error in the DataManager header where I #import Dataobject header, it says "error: expected')' before DataObject"

I don;t understand what I miss.

Thanks for the help..

+3  A: 

You forgot to define the DataObject type in your DataManager header file.

Your DataManager header file should look like this:

#import <Foundation/Foundation.h>

@class DataObject;

@interface DataManager : NSObject 

- (DataObject *)getData :(NSString*)url;

@end
Jacob Relkin
I find it preferable to forward-declare classes in interfaces to avoid circular dependencies. To do that: @class DataObject;
Graham Lee
Thank you Graham, you are right.
Akbarbuneri