#import <Foundation/Foundation.h>
@interface Gun : NSObject
@property int ZiDan;
-(void)SheJi;
@end
@implementation Gun
-(void)SheJi{
NSLog(@"枪在射击...");
}
@end
@interface Soldier : NSObject
@property Gun *gun;
-(void)KaiQiang;
@end
@implementation Soldier
-(void)KaiQiang{
[_gun SheJi];
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
Gun *gun = [Gun new];
Soldier *s1 = [Soldier new];
//给士兵一把枪
s1.gun=gun;
[s1 KaiQiang];
}
return 0;
}
由于本人英语不好 所以有些拼音代替了 勿喷
Soldier 里的实现 里面的 [_gun SheJi]; 是怎么弄的 一个是属性 一个是办法 属性调用办法??????? |
|