1

i have three classes.. say one two three.. now i have an object of class one.. i want to pass that object from class two to class three as a parameter by calling a method which is in class three.

what all steps to be taken and kindly explain with examples ..

Zaraki
  • 3,720
  • 33
  • 39
  • I’m not really sure what you are up to. Chances are that you would like to do something as asked in [this question](http://stackoverflow.com/questions/4924350)? – zoul Feb 11 '11 at 10:37
  • Can I respectfully suggest that if you want to learn objective-c, you attempt to actually learn objective-c (plenty of books and internet sites to help you with that) instead of asking a question of the form "How do I do a very fundamental basic thing in language X". Then attempt to do something with your new-found knowledge, and ask questions if you run into difficulties with the basics. – occulus Mar 01 '11 at 12:27

1 Answers1

1

Is this what you're after?

In your Class2 header declare a method that returns a Class1 pointer.

- (Class1*)objectOfClass1;

Implement Class2,

- (Class1*)objectOfClass1 {return [[Class1 alloc] autorelease];}

In your Class3 header declare a method that accepts an argument of pointer to Class1:

-(void) doSomething:(Class1 *)obj;

Class3 source, implement your logic:

-(void) doSomething:(Class1 *)obj {
    // Use your Class1 object here.
}

And you would call it on Class2 like this:

Class1 *obj1; //Object of class one
Class2 *obj2 = [[Class2 alloc] autorelease]; //object of class two
Class3 *obj3 = [[Class3 alloc] autorelease]; //object of class three

obj1 = [obj2 objectOfClass1]; //retrieve object of class one from object of class two 

[obj3 doSomething:obj1]; //pass object of class one into object of class three

Anyway, I recommend that you take a look at this simple tutorial: Learning Objective-C: A Primer

Tobias
  • 4,397
  • 3
  • 26
  • 33
Raphael
  • 7,972
  • 14
  • 62
  • 83