5

Can Anyone explain what this means:

oauth->url = [[NSURL alloc] initWithScheme:@"https" host:host path:unencodedPath];

It is variable assignment but why does it use '->' is this something to do with it being a Class method?

Codr
  • 68
  • 4

2 Answers2

8

It references the instance variable url of the oauth instance. It is pure C syntax.

Felix
  • 35,354
  • 13
  • 96
  • 143
1

Same thing it means in C/C++. Objective C objects don't use -> but C/C++ classes do.

Aaron Goselin
  • 634
  • 7
  • 19
  • 1
    I might be wrong but I thought Objective-C classes could use this syntax, especially to instanciate readonly values. Is it true? – Friedrik Jul 04 '11 at 12:30
  • I have never seen it done, but that doesn't mean you are wrong. I'm sure I'll find out eventually :) – Aaron Goselin Jul 04 '11 at 12:35
  • Yes as it turns out they can be used as Friedrik said I am looking at a library that uses it now – Codr Jul 04 '11 at 13:08
  • normally you would only be setting read-only ivars within "self", in which case you would not need to, but _could_ say `self->url =`, but in the case of a tightly cooperating class or classes that directly set the value of another instance's state the `oauth->url =` syntax is required to do so. there are other design choices that would not require this syntax, including private accessor methods – bshirley Jul 04 '11 at 18:10