ios开发-1
oc基础
NSArray *nameArr = [NSArray array];
nameArr = @[@"张三",@"李四",@"王五"];
int name =arc4random() % 3 ;
NSArray *arr = [NSArray array];
arr = @[[English new],[Japanese new],[German new] ,[Spanish new]] ;
int lan =arc4random() % 4 ;
Language *l = arr[lan];
NSDate *date = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy年MM月dd日"];
while(![l isFinish]){
int a =arc4random() % 5 +1;
date = [NSDate dateWithTimeInterval: a * 24 * 60 * 60 sinceDate:date];
NSLog(@"%@ %@ 学习%@ tour %d unit %d", nameArr[name],[dateFormatter stringFromDate: date],[l getName],[l getTour], [l getUnit]);
[l learnOneUnit];
}
声明一个数组并初始化
NSArray *nameArr = [NSArray array];
nameArr = @[@"张三",@"李四",@"王五"];
NSArray *arr = [NSArray array];
arr = @[[English new],[Japanese new],[German new] ,[Spanish new]] ;
获取随机数
int name =arc4random() % 3 ;
int lan =arc4random() % 4 ;
声明日期类型
NSDate *date = [NSDate date];
声明日期格式化
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy年MM月dd日"];
使用格式化输出日期
NSLog(@"%@",[dateFormatter stringFromDate: date])
类的声明
@interface Language : NSObject {
NSInteger progress_tour;
NSInteger progress_unit;
}
- (void)learnOneUnit;
- (NSInteger)getTour;
- (NSInteger)getUnit;
- (bool)isFinish;
- (NSString *)getName;
@end
@interface English : Language
- (NSString *)getName;
@end
类的实现
@implementation Language
-()init{
if (self=[super init]) {
progress_tour = 1;
progress_unit = 1;
}
return self;
}
- (void)learnOneUnit{
progress_unit ++;
if (progress_unit == 5) {
progress_unit = 1;
progress_tour ++;
}
}
- (NSInteger)getTour;{
return progress_tour;
}
- (NSInteger)getUnit{
return progress_unit;
}
- (bool)isFinish{
return progress_tour > 8;
}
- (NSString *)getName{
return @"name";
}
@end
@implementation English
- (NSString *)getName{
return @"英语";
}
使用类的方法
[l getName]