Pointers on Objective-c

后端 未结 2 1413
日久生厌
日久生厌 2021-01-13 22:24

From what I understand (and please correct me if I\'m wrong):

int x, count = 10;
int *hello;
hello = &count;
x = *hello;

Here the varia

相关标签:
2条回答
  • 2021-01-13 22:41

    All the usage of objects in objective c is done through object references, e.g. pointers.

    • The Objective C syntax lets you treat objects without dereferencing them, this is different than C / C++ for that matter.
    • str is an object reference of type NSString (as myFraction) and @"Programming can be a headache" is an object reference of type NSString as well, so you can assign it to str.
    0 讨论(0)
  • 2021-01-13 22:57

    Additional to Binyamin

    • Everything inside the brackets [ ] is objective-C and not simple C (so [*object message] is not common to use)
    • [object message], you send the "message" to your object, and the object responds with something (he can return something or he can do something without anything in return).
    • Everything with a * on the left is pointer. So *str is a pointer. And where is it point? to an object NSString. The @"blabla" returns the adress of one CONSTANT string that has generated directly by the compiler.
    • NSLog (@"%@\n", str); here the %@ calls the +Description class method of NSString object called str. By default the description of an NSString Object returns the value of the string (the text). %@ is not a simple replace like the %d with numbers (int,double etc). All objects have +Description method that inherit from the NSObject (note is Class method and not instant).

    description

    Returns a string that represents the contents of the receiving class.

    • (NSString *)description
    0 讨论(0)
提交回复
热议问题