所以我得到了類:
DataFetcher.h奇怪的錯誤 - 可以訪問NSURLConnection的&NSMutableData的描述方法,但不是他們的ivars
#import <Foundation/Foundation.h>
@interface DataFetcher : NSObject
{
NSURLConnection *networkConnection;
NSMutableData *recievedData;
BOOL isFetchingFinished;
}
@property (nonatomic, retain) NSMutableData *recievedData;
@property (nonatomic, retain) NSURLConnection *networkConnection;
- (void)fetchDataWithRequest:(NSMutableURLRequest *)request;
DataFetcher.m:
#import "DataFetcher.h"
@implementation DataFetcher
@synthesize recievedData;
@synthesize networkConnection;
- (id)init
{
self = [super init];
if (self) {
NSMutableData *data = [[NSMutableData alloc] initWithLength:0];
self.recievedData = data;
[data release];
}
return self;
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"Connection Error:%@\n Failure Reason:%@", [error localizedDescription], [error localizedFailureReason]);
[networkConnection release];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.recievedData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[networkConnection release];
NSLog(@"%@", self.recievedData.length);
[self processData];
}
- (void)fetchDataWithRequest:(NSMutableURLRequest *)request
{
NSURLConnection *aConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
self.networkConnection = aConnection;
[aConnection release];
[self.networkConnection start];
if(!self.networkConnection)
{
NSLog(@"Connection failed! recieved nil at alloc point");
}
}
- (void)dealloc
{
[super dealloc];
[recievedData release];
}
@end
正常情況下,它由於EXC_BAD_ACCESS(NSZombie不會檢測到任何東西)而崩潰。 我注意到,如果你打開connectionDidFinishLoading
self.recievedData.length
只是self.recievedData
,它不會崩潰,看起來像有一些數據在那裏。同樣的事情,我得到的self.networkConnection
- 如果我只是打印self.networkConnection
,它的確定,但如果我打印self.networkConnection.retainCount
(例如,任何伊娃都會工作),它會崩潰與相同的信號。
我似乎無法把握問題的所在,我一直在尋找它安靜了一會兒,我會感謝一些幫助,這:)
TNX!
哦,我把它與此代碼:
DataFetcher *fetcher = [[DataFetcher alloc] init];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.google.com"]]; [fetcher fetchDataWithRequest:request]; [fetcher release]; [request release];