Search code examples
iosobjective-cxcodensrange

How to use NSRange


I am using NSRange with an Attributed string, but I don't fully understand which parts of the text will be bolded and which are not. This is what I tried:

NSRange boldedRange = NSMakeRange(2, 4);

What exactly does the 2 stand for and the 4 stand for?

Thanks in advance for anyone who contributes to this post


Solution

  • It says as:

    NSMakeRange(<#NSUInteger loc#>, <#NSUInteger len#>)
    

    So in your case:

    NSRange boldedRange = NSMakeRange(2, 4);
    

    2 is the starting location.

    4 is the character count till what it will use.

    Ex. If you use boldedRange on TYPEWRITER, it will change it to TYPEWRITER