5

I stumbled across the following and can't seem to work out why this works. Please can you explain why I don't need to use a pointer before range?

NSString *d = @"The quick brown fox";
NSRange range = [d rangeOfString:@"brown"];
Macmade
  • 52,708
  • 13
  • 106
  • 123
vboombatz
  • 409
  • 6
  • 17

1 Answers1

9

NSString is an object type. All object types are pointers and can't be created on the stack. NSRange is a C-struct. Structs can be created on the stack, and thus aren't necessarily all pointers.

There isn't a good guide to know which ones are objects, and which are structs. You'll just have to check for each type as you move forward.

Joshua Weinberg
  • 28,598
  • 2
  • 97
  • 90
  • +1 To the OP: remember that Objective-C is a super-set of C, adding OOP features. But even if you can code in a OOP way, you still have to know (at least) a few C basics. – Macmade Nov 30 '11 at 23:30
  • A solid understanding of heap vs stack allocations would be very handy here. – Joshua Weinberg Nov 30 '11 at 23:31
  • 1
    Not even a solid one... Just a few basics would actually help, IMHO : ) – Macmade Nov 30 '11 at 23:33