Reputation: 249
Pointers
If you have experience with C, C++, or Objective-C, you may know that these languages use pointers to refer to addresses in memory. A Swift constant or variable that refers to an instance of some reference type is similar to a pointer in C, but is not a direct pointer to an address in memory, and does not require you to write an asterisk (*) to indicate that you are creating a reference. Instead, these references are defined like any other constant or variable in Swift.
Here is the interpretation of "Pointers" from Apple doc. We all know that in C++ or Objective-c, the pointer point directly to the address in memory. But in Swift, Apple says A Swift constant or variable that refers to an instance of some reference type is similar to a pointer in C, but is not a direct pointer to an address in memory,
it confuses me a lot. My question is what is the scene behind reference type, if it is not a direct pointer to an address in memory, where is it point to?
Any hint or clue will be greatly appreciated.
Upvotes: 6
Views: 1041
Reputation: 11133
Classes are references types, so variables (var) and constants (let) that reference them are effectively pointers "behind the scenes". What the documentation is trying to get at is that this is hidden from the programmer. There are no pointer operators in Swift.
Upvotes: 1