【发布时间】:2013-03-19 04:15:34
【问题描述】:
我在这样的方法中使用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。
我做错了什么?
【问题讨论】:
标签: ios objective-c xcode objective-c-blocks