Search code examples
objective-ccocoa-touchios7nsrangenscharacterset

Is it possible to call "location" on rangerOfCharacterFromSet without dot notation in objective-c?


I am trying to write this without dot notation but can't figure it out:

[[textField text] rangeOfCharacterFromSet:someInstanceVar].location

I keep getting bad receiver type NSRange (aka '_struct NSRange')

Is this not possible?

Kind regards


Solution

  • You cannot call that without the dot. rangeOfCharacterFromSet returns a NSRange, which is a plain C struct:

    typedef struct _NSRange {
        NSUInteger location;
        NSUInteger length;
    } NSRange;
    

    and not an Objective-C object. .location accesses the first member of that struct and is pure C syntax. That has nothing to do with the dot-notation for properties, or with method calls.