Pointers on Objective-c

后端 未结 2 1446
日久生厌
日久生厌 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: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

提交回复
热议问题