因此,我正从This Tutorial着手,尝试使用自建的应用程序接口在我的应用程序中构建一个XML阅读器。我正在尝试读取一个xml,并且一直收到这个错误:
*** -[CFString release]: message sent to deallocated instance 0x68675a0我不会释放或释放任何东西,我会让AutoRelease来处理所有这些事情。下面是我对该方法的调用:
self.dtContact = [DTContactParser loadDTC];
if (_dtContact != nil) {
for (DTContact *dtc in _dtContact.contacts) {
NSLog(@"%@", dtc.description);
}
}
NSLog(@"done");当它发送NSLog(@"done");,然后抛出错误时,我得到了我的错误。
下面是DTContactParser的loadDTC
+ (DTCXMLResponse *)loadDTC {
NSString *filePath = [self dataFilePath:FALSE];
NSData *xmlData = [[NSMutableData alloc] initWithContentsOfFile:filePath];
NSError *error;
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:xmlData
options:0 error:&error];
if (doc == nil) { return nil; }
DTCXMLResponse *dtcxmlr = [[DTCXMLResponse alloc] init];
NSArray *dtcontacts = [doc.rootElement elementsForName:@"DetectiveContact"];
for (GDataXMLElement *dtcontact in dtcontacts) {
// Let's fill these in!
NSString *description;
int dtcid;
// Name
NSArray *descriptions = [dtcontact elementsForName:@"description"];
if (descriptions.count > 0) {
GDataXMLElement *firstName = (GDataXMLElement *) [descriptions objectAtIndex:0];
description = firstName.stringValue;
} else continue;
// Level
NSArray *ids = [dtcontact elementsForName:@"idDetectiveContact"];
if (ids.count > 0) {
GDataXMLElement *firstID = (GDataXMLElement *) [ids objectAtIndex:0];
dtcid = firstID.stringValue.intValue;
} else continue;
DTContact *dtcontact = [[DTContact alloc] initWithName:description dtId:dtcid];
[dtcxmlr.contacts addObject:dtcontact];
return nil;}}
下面是DTContact:
#import "DTContact.h"
@implementation DTContact
@synthesize description = _description;
@synthesize dtId = _dtId;
- (id)initWithName:(NSString *)description dtId:(int)dtId{
if ((self = [super init])) {
self.description = description;
self.dtId = dtId;
}
return self;
}@end
任何帮助都将不胜感激。
发布于 2012-01-05 04:42:37
Using this answer to a separate question,我已经在我的GDATAXML库上禁用了ARC,它停止了导致错误的发生。
https://stackoverflow.com/questions/8717936
复制相似问题