我收到警告::不兼容的指针类型在下面的代码中从'NSData'分配给'NSMutableData'
-(void) connectionDidFinishLoading:(NSURLConnection *) connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[[NSString alloc] initWithBytes: [webData mutableBytes] length [webData length] encoding:NSUTF8StringEncoding] autorelease];
theXML = [theXML stringByReplacingOccurrencesOfString:@"<" withString:@"<"];
theXML = [theXML stringByReplacingOccurrencesOfString:@">" withString:@">"];
NSLog(@"%@",theXML);
if( xmlParser )
{
xmlParser = nil;
[xmlParser release];
}
NSMutableString *str = [[NSMutableString alloc]initWithString:theXML];
webData = [str dataUsingEncoding:NSUTF16StringEncoding];//WARNING
xmlParser = [[[NSXMLParser alloc] initWithData:webData] autorelease];
[xmlParser setDelegate:self];
[xmlParser setShouldResolveExternalEntities: YES];
[xmlParser parse];
[connection release];
}
答案 0 :(得分:5)
使用
webData = [NSMutableData dataWithData:[str dataUsingEncoding:NSUTF16StringEncoding]];
答案 1 :(得分:2)
您无法将NSData分配给NSMutableData。 NSMutableData包含允许它变异的逻辑,如果你将它指向NSData对象,这个逻辑就会消失。你应该做的是使用以下语法附加数据:
[webData appendData:[str dataUsingEncoding:NSUTF16StringEncoding]];