0

I suppose the default scope for ivars is @protected.

I declared a variable like this in the header file of a class:

{
int _test1;
}

But I could print this variable _test1 using NSLog in a totally unrelated object.

NSLog(@"%d", _test1);

Why is _test1 available to the second object?

Where can I find the latest ivars scope rules?

Thanks in advance.

1 Answers1

0

If you are talking objective-c v1, then you are correct... unless otherwise defined (by using the @public, @private, or @packaged keywords), ivars will default to @protected.

You're not showing your code, so I can't be certain, but I wonder if you have the same "issue" as described in this other post: Objective-C - Private vs Protected vs Public

For objective-c 2 this is kind of "deprecated". This article pretty much describes how to do this now: http://robsprogramknowledge.blogspot.com/2011/08/objective-c-property.html

The best place to go for the latest objective-c documentation is probably developer.apple.com... Here's a link to the latest programming manual: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html

Community
  • 1
  • 1
Oscart
  • 16