0

I've to searching for in NSMutableAttributedString* textToAnalize; the number of characthers with a specific attribute.

So in this code

while (index<[[self textToAnalize]length]) {
    NSRange range;
    id value=[self.textToAnalize attribute:attributeName atIndex:index effectiveRange:&range];
    if (value) {
        [text appendAttributedString:[self.textToAnalize attributedSubstringFromRange:range]];
         index=range.location+range.length;
    }
    else index++;

there's a local variable called range and for method attribute: atIndex: effectiveRange: it is passed as argument of effectiveRange

Now I'm wondering how this range is setted automatically when this method find the attribute. I'll try to explain it better :

NSRange range is local not initialized variable so inside it, location and length has 0 0 values.

Below the method there's a update of index with the value of location and length but nobody setted the values of those. My teacher said that it's automatically setted by the method above but I've searched in Apple Documentation pages but I've not discovered an explanation.

  • Did you notice that you wrote `effectiveRange:&range` and not `effectiveRange:range`? It's the same than `getRed:green:blue:alpha:` method of `UIColor`. Also did you read the method declaration: `effectiveRange:(NSRangePointer)aRange` (`NSRangePointer`, not `NSRange`). – Larme Aug 02 '16 at 08:58
  • Yes, I took note of that now but don't understand the logic whereby values of range are updated automatically –  Aug 02 '16 at 09:34

0 Answers0