Still, what would be the harm in saying "you've got the principle fine - the issue isn't with the code you've posted" if that is indeed the case? That would be almost as good as somebody identifying the actual issue. People asking questions aren't always looking for someone to hand something on a platter to them, they're just looking to get unstuck. If they think the issue is with A, but actually there's no problem there at all, that is very useful to know in itself.
If I had the full answer at the time, I probably would have posted it. But I didn't, so I didn't.
Here's what I did before my first post:
I looked at your code. It looked fine on first inspection. For a method so small, my next step is usually to paste it into a file and compile it, then run it. Unfortunately, there wasn't enough code to do that without having to:
A. Create the class header.
B. Create the class implementation (including relevant init method).
C. Write a main() that instantiated the class (with relevant alloc and init being called)
D. Add code to the class that worked in the same way you described as working (i.e. when the method is invoked on self).
Steps A-D were more than I wanted to do at the time, because I had other real work to do (finished and working now, so now I have more time to reply).
So I looked at the posted code again, and thought about possible failure scenarios. Well, the output values (140734799801952, 4300215136) look like stack garbage to me, which suggests an uninitialized variable. Sure enough, you have an uninitialized variable at the declaration of charRange. So whatever was happening between that declaration and the NSLog was clearly having no effect. One of simplest and most common ways for some method to have no effect is when its called on nil. Since you didn't show any code assigning a value to myObjectInstance, I arrived at my posted question:
What is the value of myObjectInstance when it fails?
The subsequent leading questions were there to hint at the simple common case when calling a method has no effect.
Later on, when you still hadn't posted code showing the assignment of something useful to myObjectInstance, it seemed necessary to explain why posting complete and compilable code is actually necessary for debugging something. In short, I wanted you to provide the code for the steps A-D I outlined above.
It all comes down to a very simple thing: I wanted to compile and run the code myself, so I could see it work (or not work) myself. I could have written my own code that does that, but what does that prove? My code for doing those things isn't your code for doing those things, and the problem was clearly in
your code. More specifically, your
unposted code.
How was I able to deduce that the problem was in your unposted code? Because you said your posted code worked in a specific case, although you didn't ever post complete code for it. That is, you never actually showed the code for "When the method is part of the same object that's calling it, it works fine." So, there was one case where it worked and you got the results you expected. Clearly,
something was working, even though no one else could see your complete code for it. So even in the working case, I'd have to write code, guessing that what I would write would be similar to what you wrote. Sorry, didn't have time for that, either.
By the time I did have time to write longer explanations, you still hadn't posted any additional code that was testable or compilable, though you had said you found there was a nil pointer. Yet once again, you didn't post code for it, so once again we went for a ride on the "Post your code" carousel.
And that's pretty much how we got here.