2012-01-03 93 views
0

因此,我正在從This Tutorial開始工作,並嘗試使用自建的api將XML讀取器構建到我的應用程序中。我試圖通過XML閱讀,並不斷收到此錯誤:AutoRelease干擾數據處理

*** -[CFString release]: message sent to deallocated instance 0x68675a0 

我不釋放或重新分配任何東西,我讓自動釋放處理這一切。這是我的呼籲方法:

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

任何幫助將非常感激。

+1

是否啓用ARC? – 2012-01-03 20:25:16

+0

是的,我已啓用它。 – 2012-01-03 20:35:28

回答