如何在目标C(iPhone)中通过引用传递值 [英] How to pass values by reference in objective C (iphone)
本文介绍了如何在目标C(iPhone)中通过引用传递值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个非常基本的问题.我是新来的iPhone程序员. 我的问题是谁能告诉我如何通过引用obj中的函数来传递值. C?我知道如何在VB和C#中执行此操作.但是不知道在Obj c中怎么做.
I have a very basic question. I'm a new iPhone programmer. My question is can anybody tell me how can I pass values by reference to a function in obj. C? I know how to do it in VB and C#. But don't know how to do it in Obj c.
谢谢
推荐答案
Objective-C中的按引用传递与C中的传递引用相同.
Pass-by-reference in Objective-C is the same as it is in C.
等效于以下C#代码:
void nullThisObject(ref MyClass foo)
{
foo = null;
}
MyClass bar = new MyClass();
this.nullThisObject(ref bar);
assert(bar == null);
是
- (void)nilThisObject:(MyClass**)foo
{
[*foo release];
*foo = nil;
}
MyClass* bar = [[MyClass alloc] init];
[self nilThisObject:&bar];
NSAssert(bar == nil);
和
- (void)zeroThisNumber:(int*)num
{
*num = 0;
}
int myNum;
[self zeroThisNumber:&myNum];
NSAssert(myNum == 0);
这篇关于如何在目标C(iPhone)中通过引用传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文