0

An example that made me ask is:

Xcode tells me to

// Get the new view controller using [segue destinationViewController].

but i did it like this

destViewController = segue.destinationViewController;

Im just starting to learn objective-c, i'v only ever wrote c++. Could someone elaborate on the [ ] and the difference between segue.destinationViewController and [segue destinationViewController] and when you should use one or the other? (I don't know what terminology to search)

destinationViewController just holds the pointer to a view controller and is not a method right? This is whats confusing my i thought [x y] syntax is for calling methods so why does xcode tell me to do this?

nicwhitts
  • 190
  • 1
  • 3
  • 22
  • 1
    the terminology to search for can be something like "method call vs. dot notation". They're equivalent apart from the fact that `[obj method]` can't be assigned to (whereas `obj.prop` can), and the dot notation triggers a hard error if the compiler can't find the method/property declaration, while unknown method calls only result in a warning (and a runtime "unrecognized selector" exception). –  Oct 12 '13 at 17:03
  • I don't understand how destinationViewController can be called using the method call syntax when it is declared as a property id `@property (nonatomic, readonly) id destinationViewController;` – nicwhitts Oct 12 '13 at 18:14
  • Read a beginner Objective-C tutorial, then. My comment above says "they're equivalent [...]" for a reason. –  Oct 12 '13 at 18:16

0 Answers0