JavaのバックグラウンドからObjective-Cに来ています。なぜ次のコードが例外を生成するのか理解できない。なぜObjective Cの対象外のオブジェクトメンバーですか?
@interface Stopwatch : NSObject {
NSDate *start;
int mode;
}
@property(nonatomic,assign) NSDate *start;
@property(nonatomic,assign) int mode;
@end
@implementation Stopwatch
@synthesize start, mode;
-(id) init{
self = [super init];
if(self){
start = [NSDate date];
mode = -1;
}
return self;
}
@end
@interface StopwatchController : NSObject {
Stopwatch *stopwatch;
}
@property (nonatomic,assign) Stopwatch *stopwatch;
- (void) useStopwatch:(Stopwatch*)aStopwatch;
- (void) updateStopwatch;
@end
@implementation StopwatchController
@synthesize stopwatch;
- (void) useStopwatch:(Stopwatch*)aStopwatch{
stopwatch = aStopwatch;
}
- (void) updateStopwatch{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setTimeStyle:NSDateFormatterMediumStyle];
[dateFormat setDateStyle:NSDateFormatterMediumStyle];
NSString *string = [dateFormat stringFromDate:stopwatch.start];
NSLog(@"%@",string);
}
@end
したがって、次のコードが実行されると、私はstopwatch.startストップウォッチ範囲外であるが、ではないことがわかり?
Stopwatch *sw = [[Stopwatch alloc]init];
StopwatchControlelr *swc = [[StopwatchController alloc]init];
[swc useStopwatch:sw];
[swc updateStopwatch];