OC类方法的调用

时间:2021-09-27 00:15:59

有个Person类,有个Phone类,Person类想使用Phone类中打电话和发短信的方法

1、Phone.h         Phone有kind和color属性  ,方法定义的时候将用到的参数都定义进去

 #import <Foundation/Foundation.h>

 @interface ZSPhone : NSObject
@property(strong,nonatomic)NSString *kind;
@property(strong,nonatomic)NSString *color;
-(void)call:(NSString *)name andWithColor:(NSString *)color andWithKind:(NSString *)kind andWithWhom:(NSString *)name2; -(void)sendMessage:(NSString *)name andWithColor:(NSString *)color andWithKind:(NSString *)kind andWithWhom:(NSString *)name2;
@end

2、Person.m          //导入Phone.h,Person类中定义一个usephone方法,调用Phone中的call方法和sendMessage方法

 -(void)usephone{
ZSPhone *phone=[[ZSPhone alloc]init]; //使用ZSPhone类创建对象
[phone call:@"小花" andWithColor:@"红色" andWithKind:@"小米" andWithWhom:@"虎哥哥"];
[phone sendMessage:@"小花" andWithColor:@"红色" andWithKind:@"小米" andWithWhom:@"虎哥哥"];

OC类方法的调用