我enumerateLinguisticTagsInRange
在这样的方法中使用:
[nonAttributedString enumerateLinguisticTagsInRange:stringRange
scheme:NSLinguisticTagSchemeTokenType
options:NSLinguisticTaggerOmitWhitespace | NSLinguisticTaggerOmitPunctuation | NSLinguisticTaggerJoinNames
orthography:[NSOrthography orthographyWithDominantScript:@"Latn" languageMap:languageMap]
usingBlock:^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop) {
// If the token is a word...
if ([tag isEqualToString:@"Word"])
{
// (And add to the tracking dictionary)
NSMutableDictionary *wordAndRange = [[NSMutableDictionary alloc] init];
[wordAndRange setObject:[NSNumber numberWithInt:(tokenRange.location + tokenRange.length)] forKey:[nonAttributedString substringWithRange:tokenRange]];
[typedWordsAndRanges addObject:wordAndRange];
}
}];
标记器工作正常,但不将范围限制为stringRange
. 它完整地列举nonAttributedString
了一遍。
如果我在此块上方包含以下日志:
NSLog(@"########### stringRange.location = %d", stringRange.location);
NSLog(@"########### stringRange.length = %d", stringRange.length);
NSLog(@"########### substring = %@", [nonAttributedString substringWithRange:stringRange]);
我得到以下输出:
2013-03-18 21:06:27.744 WEJ[13231:c07] ########### stringRange.location = 10
2013-03-18 21:06:27.745 WEJ[13231:c07] ########### stringRange.length = 4
2013-03-18 21:06:27.805 WEJ[13231:c07] ########### substring = de
所以stringRange
是正确的。但是,它仍然在完整地列举nonAttributedString
。
我究竟做错了什么?