3日目-パッケージ
2953 ワード
//
// main.m
// 02-
//
// Created by Apple on 14/11/20.
// Copyright (c) 2014 itcast. All rights reserved.
//
#import <Foundation/Foundation.h>
/*
:
1、 , ,
2、
@public , ,
1、 , , , ,
2、
1、 getter setter
2、setter : ,
1、
2、
3、 set + ,
4、 ,
3、getter : ,
1、
2、 ,
3、
4、
*/
#import "CZCat.h"
/**
, getter setter
1>
(1)
*
*
(2)
* setter getter
*/
@interface CZCar : NSObject
{
int _wheels;// ‘
double _speed;//
}
//_wheels setter
- (void) setWheels:(int) wheels;
- (int) wheels;
- (void) setSpeed:(double) speed;
- (double) speed;
@end
@implementation CZCar
//_wheels setter
- (void) setWheels:(int) wheels
{
_wheels = wheels;
}
- (int) wheels
{
return _wheels;
}
- (void) setSpeed:(double) speed
{
_speed = speed;
}
- (double) speed
{
return _speed;
}
@end
int main(int argc, const char * argv[]) {
CZCat *cat = [CZCat new];
// cat->_age = -100;
[cat setAge:100];
[cat setName:@" "];
NSLog(@"age = %d,name = %@",[cat age],[cat name]);
return 0;
}
//
// CZCat.h
// 1120-
//
// Created by Apple on 14/11/20.
// Copyright (c) 2014 itcast. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface CZCat : NSObject
{
// @public
int _age;
NSString * _name;
}
// , , getter , setter
// setter , ,
//age (setter)
/*
1、
2、
3、 set + ,
4、 ,
*/
- (void) setAge:(int) age;
//age (getter )
/*
1、
2、 ,
3、
4、
*/
- (int) age;
//setter
- (void) setName:(NSString *) name;
//getter
- (NSString *) name;
@end
//
// CZCat.m
// 1120-
//
// Created by Apple on 14/11/20.
// Copyright (c) 2014 itcast. All rights reserved.
//
#import "CZCat.h"
@implementation CZCat
// ,
/*
, self
, , self
*/
- (void) setAge:(int) age
{
// int _age = 10;
// self->_age = age;
if (age < 0) {
NSLog(@" 0");
return;
}
_age = age;
}
// getter
- (int) age
{
return _age;
}
//setter
- (void) setName:(NSString *) name
{
_name = name;
}
//getter
- (NSString *) name
{
return _name;
}
@end