As I move into more direct programming with Obj-C and making my own Classes
(usually Controllers or Delegate of other Classes that I’ve found and downloaded)
I have a question about properties. As many of the Classes and examples that I find
seem to do things quite differently.
What is the difference between Classes that implement something like:
@interface Class : NSView
{
IBOutlet NSColorWell *myBackgroundWell;
IBOutlet NSColorWell *myLineWell;
IBOutlet NSButton *myHoldButton;
NSColor *backgroundColor;
NSColor *lineColor;
CGPoint* waveformPoints;
UInt32 waveformPointsCount;
}
- (void) setBackgroundColor:(NSColor*) color;
- (void) setLineColor:(NSColor*) color;
- (IBAction) changeBackgroundColor: (id) sender;
- (IBAction) changeLineColor: (id) sender;
@end
and something like:
@interface SubClass : Class
@property (nonatomic, assign) BOOL shouldOptimizeForRealtimePlot;
@property (nonatomic, assign) BOOL shouldCenterYAxis;
@property (nonatomic, strong) EZAudioPlotWaveformLayer *waveformLayer;
// bunch of methods
@end
THIRD - which uses @synthesize in method file
@interface AppDelegate2 : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window2;
@property (assign) IBOutlet WaveFormViewOSX *wfv2;
- (IBAction)loadAudioFile:(id)sender;
@end
////////////////////// and in it’s .m file
@implementation AppDelegate2
@synthesize window2 = _window;
@synthesize wfv2 = _wfv;
// some methods
@end
FORTH: and some that have their properties both in the brackets and defined
@interface ClassFour : NSView
{
IBOutlet NSColorWell *myBackgroundWell;
NSColor *backgroundColor;
NSColor *lineColor;
CGPoint* waveformPoints;
UInt32 waveformPointsCount;
NSString* stringOne;
NSString* stringTwo;
}
@property (assign) IBOutlet NSColorWell * myBackgroundWell;
@property (assign) NSColor * backgroundColor;
@property (assign) NSColor * lineColor;
@property (assign) CGPoint * waveformPoints;
@property (assign) NSColor * lineColor;
@property (assign) NSString * stringOne;
@property (assign) NSString * stringTwo;
@property (assign) NSString * stringThree;
@property (assign) CGFloat songLength;
@end
I understand with @synthesize that compiler will automatically implement the
setters and getters for us.
Are the properties in the { } brackets instance variable of the Class?
And then say the properties stringThree and songLength local Class Variables
that are only available inside the class? IE I can’t ask for
ClassFourInstance.stringThree
Next about instance variables in my methods:
when I want to be referring to the Instance Variable of stringTwo in one of my methods.
Do I need to make sure that I writing it like:
NSString* newStringFour = [_stringTwo stringByAppendingString:(@" - Completed")];
and what is the difference here if I was to use “self”:
NSString* newStringFive = [self.stringTwo stringByAppendingString:(@" - Not Completed")];
and if I’m using the
@synthesize stringTwo = _stringTwo;
or Which I understand is kinda shorthand for the above and will automatically
synthesize it to _stringTwo
@synthesize stringTwo;
will then using stringTwo in my methods always then refer to the instances
“version” of stringTwo? am I able to just write:
NSString* newStringSix = [stringTwo stringByAppendingString:(@" - V06")];
Is the using the underscore just a way of keeping track in your own head
that your using an instance varable?
How does “self” come into play when the class is being used as an instance?
thanks for help.
Kerry