我看了一段关于ios7编程的视频,并在下面看到了一段代码。NSrange在这里工作?
我无法真正了解变量范围如何在这里工作。
我们创建一个NSrange变量范围,并且永远不会给它一个值,所以我认为&范围指针应该返回nil。
那么如何在有效范围内使用以及range.location和range.length中的值是什么?
非常感谢你的帮助!
- (NSMutableAttributedString *)charactersWithAttribute:(NSString *)attributeName
{
NSMutableAttributedString *characters = [[NSMutableAttributedString alloc] init];
int index = 0;
while(index < self.textToAnalyze.length)
{
NSRange range;
id value = [self.textToAnalyze attribute:attributeName atIndex:index effectiveRange:&range];
if(value)
{
[characters appendAttributedString: [self.textToAnalyze attributedSubstringFromRange:range]];
index = range.location+range.length;
}
else{
index++;
}
}
return characters;
}
查看'attribute:atIndex:effectiveRange:'的代码。注意它在'NSRange'指针中传递的内容。 – rmaddy 2014-10-17 18:15:17