我无法更改函数内实例变量的值。
我定义了一个类:
// info.h
#import <Foundation/Foundation.h>
@interface NSMyObject : NSObject
{
NSInteger i;
}
-(void) setI:(NSInteger)v;
@end
#import "info.h"
@implementation NSMyObject
-(void) setI:(NSInteger)v ;
{
i=v;
}
- (void)dealloc {
[super dealloc];
}
@end
我用参数 temObj 调用一个函数“myFunction”,它是一个 NSMyObject 实例。
myFunction(temObj);//temObj is NSMyObject
在函数中,我可以更改参数的实例变量的值obj
。
-(void)myFunction:(NSMyObject*) obj;
{
[obj setI:0];
}
...期望这会改变temObj
.
但是当我检查obj
函数中的操作结果时myFunction
,值temObj.i
并没有改变。
欢迎任何评论
谢谢