What does "@public" mean in Objective-C?

After reading the question on @private, I understand how this works. However, since all variables are @protected by default, and you cannot really access the variable without defining access, what does @public do? When do you use it?

+3
source share
4 answers

When do you use it? When you need it public. To access it from outside this class (without any additional accessories), that is. :)

+2
source

@public means ivar is available anywhere.

@private means ivar is available for class instances

@protected , ivar .

ivar , C → .

foo->instanceVarible = xyzzy;

? : . @private ( IBOutlets) accessors .

+5

@public - . , , @public, . . , .

0

.

, @private , . , , , ( ).

@protected , . . , , Objective C setter getter . @protected .

@public . , , /, - . , , .

, @public - C.

You can, of course, not define any accessories for the class variable because they are internal to the class or because you declare it as @public, but since Objective-C makes it easy to prototype them @propertyand @synthesizeit doesn't make much sense. Class internal variables do not need setters / getters, because any class method can access them directly.

0
source

Source: https://habr.com/ru/post/1744344/


All Articles