Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access a variable from inner class

Tags:

objective-c

 //MainClass.m 

 @interface InnerClass : NSObject{

 }
 @end

 @implementation InnerClass

 -(void)run{
      while(isActive){//want to access this variable which defined in MainClass
      //do something
      }
 }

 @end

 @interface MainClass : NSObject{
      BOOL isActive;
 }
 @end

 @implementation MainClass


 @end

I have MainClass and it has an inner class (InnerClass). I want to access the boolean type variable (isActive) defined in MainClass class from the inner class. What I am trying to do is that the inner class will run on a separate thread and will keep checking the isActive variable on the main class and if isActive is false then it will stop running the new thread.. Thanks in advance...

like image 876
codereviewanskquestions Avatar asked Mar 17 '11 03:03

codereviewanskquestions


1 Answers

Objective-C doesn't have inner classes. Consider making isActive a property of MainClass, give InnerClass a pointer to an instance of MainClass, and let InnerClass simply access the property.

like image 163
Caleb Avatar answered Nov 13 '22 00:11

Caleb