Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何为参数指定值_Objective C - Fatal编程技术网

Objective c 如何为参数指定值

Objective c 如何为参数指定值,objective-c,Objective C,如何为参数指定值 Rs232MsgRawEncoded(const int nMsgId,const INT8U* pSrc=NULL,unsigned int nSize=0); 我已在目标C中声明上述cpp方法声明如下 -(id)initWithRS232MsgRawEncoded:(const int)nMsgId withpSrc:(const uint8_t*)pSrc withSize:(unsigned int)nSize; 在函数内部,我正在检查它是否为null或是否具有某个

如何为参数指定值

Rs232MsgRawEncoded(const int nMsgId,const INT8U* pSrc=NULL,unsigned int nSize=0);
我已在目标C中声明上述cpp方法声明如下

-(id)initWithRS232MsgRawEncoded:(const int)nMsgId withpSrc:(const uint8_t*)pSrc withSize:(unsigned int)nSize;
在函数内部,我正在检查它是否为null或是否具有某个值

我无法在目标C中将变量声明为pSrc=NULL和nSize=0
有没有办法做到这一点?

Objective-c和c不支持函数的默认参数

因此,您可以使用现有的函数,每次都将所有参数传递给它。如果没有-创建省略某些参数的新函数,并调用包含默认参数的“main”函数,例如:

-(id)initWithRS232MsgRawEncoded:(const int)nMsgId{
    return [self initWithRS232MsgRawEncoded:nMsgId withpSrc:NULL withSize:0];
}