传递参数

发布于 2024-11-07 06:01:46 字数 461 浏览 1 评论 0原文

我写了一个带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不如归去 2024-11-14 06:01:46

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

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

}

传入对本地对象的引用。

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

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];
夜夜流光相皎洁 2024-11-14 06:01:46

根据定义,“输出参数”是指向指针的指针。

您的方法应如下所示:

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

这会取消引用传入的指针以获取实际的对象引用,然后将其分配给 [receivedMessage substringFromIndex:2] 返回的内容。

调用这个方法非常简单:

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

An "out parameter" is by definition a pointer to a pointer.

Your method should look like this:

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

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:

NSString *messageCondent = nil;
NSString *mode = [myclassobject messageDecryption:message outParam:&messageCondent];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文