I have a variable declared in the header file :
@interface
int _nPerfectSlides;
and
@property (nonatomic, readwri
1. For + (void)hit
:Only have access to the self
object.
--Step 1: Remove follwing line from header file
@property (nonatomic, readwrite) int _nPerfectSlides;
--Step 2:
int _nPerfectSlides
in your class file globally.. @implementation
Eg: In .m File
#import "Controller.h"
int _nPerfectSlides // Add like this before @implementation
@implementation Controller
2. For - (void)hit
:Only have access to the instance methods
I know this is old, but it still comes up. Try making it a static. Here's I'm altering the code a bit to make it increment.
// Hit.h
#import <Foundation/Foundation.h>
@interface Hit : NSObject
+ (void)hit;
@end
// Hit.m
#import "Hit.h"
@implementation Hit
static int val = 0;
+ (void)hit {
val += 1;
[self showHit];
}
+ (void)showHit {
NSLog(@"hit value: %d", val);
}
@end
//main.m
#import <Foundation/Foundation.h>
#import "Hit.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
[Hit hit];
[Hit hit];
[Hit hit];
}
return 0;
}
An instance variable is, as its name suggests, only accessible in the instance methods (those declared with -
). Class methods (declared with +
) have no access to instance variable, no more than they have access to the self
object.
If you meant to make this an instance method, change that + to -.