我想用特定日期初始化一个 nsdate ,以便在我的所有代码中使用它,我正在这样做:
。H
@property (nonatomic, retain) NSDate *myDate;
.m
@synthesize myDate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd"];
myDate = [formatter dateFromString:@"2050-01-01"];
}
return self;
}
然后在代码中,如果我以这种方式读取 nsdate:
NSLog(@"%@",myDate);
或者如果我使用 isEqualToDate,请给我一个 exc_bad_access
为什么?