objective-c function

本文介绍了Objective-C中方法的声明方式及其与C++的对比,并详细解释了参数及函数调用的语法特点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

- (return_type)instanceMethod1:(param1_type)param1_varName :(param2_type)param2_varName;

- (return_type)instanceMethod2WithParameter :(param1_type)param1_varName andOtherParameter:(param2_type)param2_varName;

The code above is roughly equivalent to the following C++

return_type instanceMethod1(param1_type param1_varName, param2_type param2_varName);

 return_type instanceMethod2WithParameter(param1_type param1_varName, param2_type param2_varName=default);

 

Note that instanceMethod2WithParameter:andOtherParameter: demonstrates the interleaving of selector segments with argument expressions, for which there is no direct equivalent in C/C++.   ----?

 

函数参数语法

:(参数类型) 参数名称

In some cases (e.g. when writing system APIs) it is useful to add descriptive text before each parameter.

描述文字:(参数类型) 参数名称

 

函数调用:

- (int)changeColorToRed:(float)red green:(float)green blue:(float)blue;
 
[myColor changeColorToRed:5.0 green:2.0 blue:6.0];

The syntax allows pseudo-naming of arguments.

 

http://en.wikipedia.org/wiki/Objective-C

转载于:https://www.cnblogs.com/season2009/archive/2012/06/06/2538634.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值