ivars

Objective-c: why private ivars are not hidden from the outside access when using KVC

泪湿孤枕 提交于 2019-11-30 07:15:08
问题 After trying to access ivars using KVC, I have noticed that there was no protection on private and protected ivars. It doesn't matter what I put a in front of the ivar (private or protected keyword) - an ivar is always a public ivar when using KVC method "setValue". Here is my code where all of the seven ivars and properties are changeble outside the class instance: //************ interface file ***************// @interface MyClass : NSObject { @public NSNumber *public_num; @protected

Automatic iVars with @synthesize

北城以北 提交于 2019-11-29 14:43:37
问题 I understand that starting with iOS 4, there is now the ability to not declare iVars at all, and allow the compiler to automatically create them for you when you synthesize the property. However, I cannot find any documentation from Apple on this feature. Also, is there any documentation on best practices or Apple recommended guidelines on using iVars and properties? I have always use properties like this: .h file @interface myClass { NSIndexPath *_indexPath } @property(nonatomic, retain)

Objective-c: why private ivars are not hidden from the outside access when using KVC

孤街醉人 提交于 2019-11-29 02:20:54
After trying to access ivars using KVC, I have noticed that there was no protection on private and protected ivars. It doesn't matter what I put a in front of the ivar (private or protected keyword) - an ivar is always a public ivar when using KVC method "setValue". Here is my code where all of the seven ivars and properties are changeble outside the class instance: //************ interface file ***************// @interface MyClass : NSObject { @public NSNumber *public_num; @protected NSNumber *protected_num; @private NSNumber *private_num; NSNumber *private_property; } @property (retain)