Question

I have created a project and it works fine. Now I need to write some test cases. So I added and set up SenTestingKit. Then I started writing test cases by creating instances of a Class and trying to change value of some variables within that class. The problem is I have declared some variables as local (Default "protected"), and these variables could not be modified. So is there a way to test by changing instance var value without adding @property(nonatomic,retain) to each variable? Thanks in advance..

Was it helpful?

Solution 3

My aim was to modify instance variables without adding @property() to variables. I have done it by adding instance methods like

-(void)setValueOfArrayCount:(int)newValue{

     arrayCount = newValue;
}

-(int)getValueOfArrayCount{

     return arrayCount;
}

And I could invoke these methods from out side this class.

OTHER TIPS

You can make it public by using @public. you can access the member using object->member.

Objective-C is a highly introspective and reflexive language. You can access and modify all you variables without having to configure them as public.

If you actually have a setter (but is protected) you only have to do something as

[myObject performSelector:@selector(setMyiVar:) withObject:value];

If you dont have a setter for it you can always use the runtime methods to access and modified your ivar by using class_getInstanceVariable. Check it out at http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html

Hope it helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top