- #import "Person.h"
- int main(){
- Person *stu1=[[Person alloc]initWithName:@"liyi" age:21 score:24];
- Person *stu2=[[Person alloc]initWithName:@"liyi" age:31 score:24];
- Person *stu3=[[Person alloc]initWithName:@"liyi" age:1 score:24];
- Person *stu4=[[Person alloc]initWithName:@"liyi" age:61 score:24];
- Person *stu5=[[Person alloc]initWithName:@"liyi" age:41 score:24];
- int i=0,j;
- BOOL flag=YES;
-
- Person *temp=nil;
- NSArray *stuArray = [NSArray arrayWithObjects:stu1, stu2,stu3,stu4,stu5, nil];
- int count=[stuArray count];
- for(i=count-1;i>=0;i++){
- NSLog([stuArray objectAtIndex:i] );
- }
- return 0;
- }
复制代码
Person.h
- #import <Foundation/Foundation.h>
- @interface Person :NSObject
- {
- @private NSString *_name;
- @private int _age;
- @private int _score;
- }
- -(void) setName:(NSString *)name;
- -(NSString *) name;
- -(void) setAge:(int) age;
- -(int) age;
- -(void) setScore:(int) score;
- -(int) score;
- - (id) initWithName:(NSString *)name age:(int)age score:(int)score;
- @end
复制代码
Person.m
- #import "Person.h"
- @implementation Person
- -(void) setName:(NSString *)name{
-
- _name=name;
-
- }
- -(NSString *) name{
- return _name;
- }
- -(void) setAge:(int) age{
- _age=age;
- }
- -(int) age{
- return _age;
- }
- -(void) setScore:(int) score{
- _score=score;
- }
- -(int) score{
- return _score;
- }
- - (id) initWithName:(NSString *)name age:(int)age score:(int)score{
- if(self=[super init]){
- _name=name;
- _age=age;
- _score=score;
- }
- return self;
- }
- - (NSString *)description{
- return [NSString stringWithFormat:@"My Name Is %@ Age Is %d Score Is %d",_name,_age,_score];
- }
- @end
复制代码
运行的时候报错。。。
|
|