传出参数 [英] passing out parameter

查看:109
本文介绍了传出参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用out参数编写了一个方法:

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

但是,有一个问题。 out参数值未正确设置。任何人都可以帮我正确地做到这一点吗?

However, there is a problem. The out parameter value is not being set properly. Can any one help me to do this correctly?

推荐答案

创建接受指向对象的指针的方法。

Create the method to accept a pointer to the object.

-(NSString *)messageDecryption:(NSString *)receivedMessage outParam:(NSString**)messageCondent
{   
    *messageCondent = [receivedMessage substringFromIndex:2];
    return [receivedMessage substringToIndex:1];

}

传入对本地对象的引用。

Pass in the reference to the local object.

NSString *messageCondent = nil;
NSString *mode = [myclassobject messageDecryption:message outParam:&messageCondent];

这篇关于传出参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆