0
Objective-C的新手,並試圖完成一個類的最終項目。我已經創建了一個基於用戶輸入設置日期的方法,並且遇到了setter的一些麻煩。用戶首先必須選擇添加新條目的選項,然後程序應該要求用戶輸入日期並根據該輸入設置日期。基於用戶輸入的設置器方法
#import <Foundation/Foundation.h>
@interface Planner : NSObject {
NSNumber *date;
}
-(void) setDate:(NSNumber *)newDate;
-(NSNumber *) date;
@end
@implementation Planner
-(void) setDate:(NSNumber *) newDate
{
date = [[NSNumber alloc] initWithInt: newDate];
NSLog(@"Enter date");
scanf("%i", newDate);
}
-(NSNumber *) date;
{
return date;
}
@end
int main (int argc, const char * argv[])
{
int userAction;
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Planner *newPlanner = [[Planner alloc] init];
NSLog(@"Please enter 1 to add a new entry and 2 to update an existing entry");
scanf("%i", userAction);
if (userAction == 1) {
[newPlanner setDate];
}
else
NSLog(@"will update");
[pool drain];
return 0;
}