I watched a video about ios7 programming and saw piece of codes below.
I can not really understand how the variable range works here.
We create a NSrange variable range and never give it a value, so I think the &range pointer should return nil.
Then how can it be used in effectiveRange and what is the value in range.location and range.length?
Thank you so much for help!
- (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;
}