I recently started learning Objective-C. I decided to make a class called “Student” with the properties age, name, and importantly, classes. I have put the classes in an NSArray full of NSStrings. My issue is, if I define it as an @property, it automatically creates a setter and getter method for it. I dont want that in my class. How do I define an NSArray as private data in the class, without allowing for the setter and getter?
Here’s the header code:
#import <Foundation/Foundation.h>
@interface Student : NSObject
@property NSString * Name;
@property unsigned short age;
@property BOOL isFullTime;
@property NSMutableArray * Classes;
@end
[NSGreeter ThanksGuys];
You have a few popular options. Of course, you can substitute types as you wish:
A:
Place it in the header, and specify
@privateaccess.B:
Place it in the @implementation block. you could specify access, but that is not usually an issue because it is not visible to any other translation.
C:
Declare it in the class continuation:
D:
Declare as a property in the class continuation: