gpt4 book ai didi

objective-c - 什么在调用 CFStringCreateFromExternalRepresentation?

转载 作者:行者123 更新时间:2023-12-03 17:35:32 25 4
gpt4 key购买 nike

我对这个堆栈跟踪感到相当困惑(只显示了令人困惑的部分):

-[NSXMLDocument length]: unrecognized selector sent to instance 0x10187e010
An uncaught exception was raised
-[NSXMLDocument length]: unrecognized selector sent to instance 0x10187e010
(
0 CoreFoundation 0x00007fff8f5d6286 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff9213bd5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8f6624ce -[NSObject doesNotRecognizeSelector:] + 190
3 CoreFoundation 0x00007fff8f5c3133 ___forwarding___ + 371
4 CoreFoundation 0x00007fff8f5c2f48 _CF_forwarding_prep_0 + 232
5 CoreFoundation 0x00007fff8f548c66 CFDataGetLength + 118
6 CoreFoundation 0x00007fff8f5791df CFStringCreateFromExternalRepresentation + 31
7 asLJ 0x0000000100013828 +[stripHTML stripAllHtmlFromString:] + 212

特别是,我不明白对 CFStringCreateFromExternalRepresentation 的调用发生在哪里,因此我不知道代码的哪一部分 (+[stripHTML stripAllHtmlFromString:]) 导致异常。是什么原因导致调用 CFStringCreateFromExternalRepresentation?如果很明显,我做错了什么导致了异常?将来,我该如何确定正在调用 CFStringCreateFromExternalRepresentation 的内容?

这里是+[stripHTML stripAllHtmlFromString:]:

+ (NSString *)stripAllHtmlFromString:(NSString *)inputString
{
// based on code from http://sugarmaplesoftware.com/25/strip-html-tags/#comment-71

NSError *theError = NULL;
NSString *modifiedInputString = [NSString stringWithFormat:@"%@\n\n\n\n\n\n\n\n\n\n\n\n",inputString]; // adding some spare newlines at the end to ensure that things will work even with a short non-HTML string
NSXMLDocument *theDocument = [[NSXMLDocument alloc] initWithXMLString:modifiedInputString
options:NSXMLDocumentTidyHTML
error:&theError];

NSString *theXSLTString = @"<?xml version='1.0' encoding='utf-8'?>"
"<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:xhtml='http://www.w3.org/1999/xhtml'>"
"<xsl:output method='text'/>"
"<xsl:template match='xhtml:head'></xsl:template>"
"<xsl:template match='xhtml:script'></xsl:template>"
"</xsl:stylesheet>";
NSData *theData = [theDocument objectByApplyingXSLTString:theXSLTString arguments:NULL error:&theError];
[theDocument release];
return [[[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding] autorelease];
}

最佳答案

哦,实际上,可能 -objectByApplyingXSLTString:arguments:error: 返回了 NSXMLDocument 而不是 NSData。因此,对 -[NSString initWithData:encoding:] 的调用是对它认为是 NSData 的内容调用 -length,但是 NSXMLDocument 无法识别这一点。

关于objective-c - 什么在调用 CFStringCreateFromExternalRepresentation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10669479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com