传递参数
我写了一个带有 out 参数的方法:
-(NSString *)messageDecryption:(NSString *)receivedMessage outParam:(out)messageCondent
{
messageCondent = [receivedMessage substringFromIndex:2];
return [receivedMessage substringToIndex:1];
}
然后我像这样传递了参数:
NSString *messageCondent;
NSString *mode = [myclassobject messageDecryption:message outParam:messageCondent];
但是,有一个问题。输出参数值未正确设置。任何人都可以帮助我正确地做到这一点吗?
I wrote a method with an out parameter:
-(NSString *)messageDecryption:(NSString *)receivedMessage outParam:(out)messageCondent
{
messageCondent = [receivedMessage substringFromIndex:2];
return [receivedMessage substringToIndex:1];
}
Then I passed the param like this:
NSString *messageCondent;
NSString *mode = [myclassobject messageDecryption:message outParam:messageCondent];
However, there is a problem. The out parameter value is not being set properly. Can any one help me to do this correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建接受指向对象的指针的方法。
传入对本地对象的引用。
Create the method to accept a pointer to the object.
Pass in the reference to the local object.
根据定义,“输出参数”是指向指针的指针。
您的方法应如下所示:
这会取消引用传入的指针以获取实际的对象引用,然后将其分配给
[receivedMessage substringFromIndex:2]
返回的内容。调用这个方法非常简单:
An "out parameter" is by definition a pointer to a pointer.
Your method should look like this:
This dereferences the passed-in pointer to get at the actual object reference and then assigns that to whatever
[receivedMessage substringFromIndex:2]
returns.Invoking this method is quite simple: