I'm an experienced developer, but new to iOS/Objective C.
The app below builds OK (modulo any typo/cut'n'paste errors).
When I run it, it breaks in the print method, in a way that makes it look like there is some error. I cannot see what or where the error is. Probably a real newby error though!
Can anyone help me out by explaining what I am doing wrong and how to fix it?
This is a command line MacOS app, with Foundation, being built & run in XCode.
@interface DayOfYear : NSObject
- (void) print;
- (id) init : (int) day;
@end // DayOfYear
@implementation DayOfYear
int dayInYr =0;
- (id) init : (int) day {
self = [super init];
dayInYr = day;
return self;
}
- (void) print {
// NSLog(@"In print with %d", dayInYr);
} // WHEN RUN THIS IS WHERE IT BREAKPOINTS SAYING "Thread 1, breakpoint 1.1, 2.1
@end
int main(int argc, const char * argv[])
{
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
DayOfYear *d =[[DayOfYear alloc] init : 2 ];
[d print];
NSLog(@"Finished!");
}
return 0;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…