Я получаю странную ошибку EXC_BAD_ACCESS при запуске моего приложения на iOS4. В течение некоторого времени приложение работало на OS3.x довольно устойчиво, даже не видя журналов сбоев в этой области кода (или многих вообще) в дикой природе.
Я отследил ошибку до этого кода:
основной класс:
- (void) sendPost:(PostRequest*)request {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSURLResponse* response;
NSError* error;
NSData *serverReply = [NSURLConnection sendSynchronousRequest:request.request returningResponse:&response error:&error];
ServerResponse* serverResponse=[[ServerResponse alloc] initWithResponse:response error:error data:serverReply];
[request.objectToNotifyWhenDone performSelectorOnMainThread:request.targetToNotifyWhenDone withObject:serverResponse waitUntilDone:YES];
[pool drain];
}
(Примечание: sendPost запускается в отдельном потоке для каждого его вызова. PostRequest - это просто класс для инкапсуляции запроса и селектор для уведомления о завершении)
ServerResponse.m:
@synthesize response;
@synthesize replyString;
@synthesize error;
@synthesize plist;
- (ServerResponse*) initWithResponse:(NSURLResponse*)resp error:(NSError*)err data:(NSData*)serverReply {
self.response=resp;
self.error=err;
self.plist=nil;
self.replyString=nil;
if (serverReply) {
self.replyString = [[[NSString alloc] initWithBytes:[serverReply bytes] length:[serverReply length] encoding: NSASCIIStringEncoding] autorelease];
NSPropertyListFormat format;
NSString *errorStr;
plist = [NSPropertyListSerialization propertyListFromData:serverReply mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&errorStr];
}
return self;
}
ServerResponse.h:
@property (nonatomic, retain) NSURLResponse* response;
@property (nonatomic, retain) NSString* replyString;
@property (nonatomic, retain) NSError* error;
@property (nonatomic, retain) NSDictionary* plist;
- (ServerResponse*) initWithResponse:(NSURLResponse*)response error:(NSError*)error data:(NSData*)serverReply;
Это надежно завершается с ошибочным доступом в строке:
self.error=err;
... т.е. в установщике синтезированных свойств!
Я озадачен, почему это должно быть, учитывая, что код работал на предыдущей ОС и с тех пор не изменился (даже двоичный файл, скомпилированный с предыдущим SDK, вылетает так же, но не в OS3.0) и учитывая, что это простой метод свойства.
Есть идеи? Может ли реализация NSError меняться между выпусками или я упускаю что-то очевидное?