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];
}