我在以下代码中得到警告::不兼容的指针类型从'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:@"&lt;" withString:@"<"];
    theXML = [theXML stringByReplacingOccurrencesOfString:@"&gt;" 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];
}

最佳答案


webData = [NSMutableData dataWithData:[str dataUsingEncoding:NSUTF16StringEncoding]];

08-16 14:25