Search code examples
iphonexcodesdknsmutabledata

Class return NSMutabledata


I want to write a class which return NSMutableData, i have this code but couldn't manage how it return self. any help would be great.

@interface ITumblr_QueryTumblr : NSMutableData {

    NSURLConnection* connection;
    NSMutableData* data;    

}



-(void)loadImageFromURL:(NSURL*)url {

    if (connection!=nil) { [connection release]; }
    if (data!=nil) { [data release]; }
    NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
    connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

}

-(void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData {

    if (data==nil) {

        data = [[NSMutableData alloc] initWithCapacity:2048];

    }

    [data appendData:incrementalData];

}

-(void)connectionDidFinishLoading:(NSURLConnection*)theConnection {

    [connection release];
    connection=nil;

    [data release];
    data=nil;

}

Solution

  • A class doesn't return anything, though a method can. To have a method that returns data, use

    -(NSMutableData *)returnSomeData {
      return data;
    }
    

    Alternately, you can just call the property .data from an instance of your class.