4日目-selfキーワード

2369 ワード

//
//  CZPerson.m
//  1121-      
//
//  Created by Apple on 14/11/21.
//  Copyright (c) 2014  itcast. All rights reserved.
//

#import "CZPerson.h"
/*
      、         
  1、                    ,
                             
  2、               , (ˇˍˇ)  ~      ;  self   
  3、    ,       ,        ;
                                     
 
  4、            :    
                 -》      -》     
 
 self   
 1、self      ,           
 2、self         ,           
 
   :
              self   

 */

int agenew = 20;

@implementation CZPerson



-(void) changeAge:(int) age
{
//    _age = 20;
//    
////    int _age = 10;
//    
//    
//    agenew  = 30;
//    
//     _age = age;
//    
//    self->_age = age;
    [self setAge:20];
}


- (void) setAge:(int)age
{
    NSLog(@"setAge");
    _age = age;
}

- (int) age
{
    NSLog(@"agenew = %d",agenew);
    return _age;
}


+ (int) sumOfNum:(int) num andOther:(int) other
{
    return num + other;
}

+ (int) averageOfNum:(int) num andOther:(int) other
{
   return  [self sumOfNum:num andOther:other] / 2;
}


@end



#import <Cocoa/Cocoa.h>

@interface CZPerson : NSObject
{
    int _age;//  
    NSString * _name;
}

-(void) changeAge:(int) age;


- (void) setAge:(int) age;

- (int) age;


+ (int) sumOfNum:(int) num andOther:(int) other;


+ (int) averageOfNum:(int) num andOther:(int) other;


@end

#import "CZPerson.h"
/*
      、         
  1、                    ,
                             
  2、               , (ˇˍˇ)  ~      ;  self   
  3、    ,       ,        ;
                                     
 
  4、            :    
                 -》      -》     
 
 self   
 1、self      ,           
 2、self         ,           
 
   :
              self   

 */

int agenew = 20;

@implementation CZPerson



-(void) changeAge:(int) age
{
//    _age = 20;
//    
////    int _age = 10;
//    
//    
//    agenew  = 30;
//    
//     _age = age;
//    
//    self->_age = age;
    [self setAge:20];
}


- (void) setAge:(int)age
{
    NSLog(@"setAge");
    _age = age;
}

- (int) age
{
    NSLog(@"agenew = %d",agenew);
    return _age;
}


+ (int) sumOfNum:(int) num andOther:(int) other
{
    return num + other;
}

+ (int) averageOfNum:(int) num andOther:(int) other
{
   return  [self sumOfNum:num andOther:other] / 2;
}


@end