Bramble
Bramble

Reputation: 1395

How do I return CGpoint function?

If i have this function:

 -(CGPoint)limitPosition:(CGPoint)position {
          //code here

              return position;
      }

how do I return it to a variable?

This:

CGPoint a;
CGPoint b;

a = [self limitPosition: b]; 

Doesnt work.

Upvotes: 0

Views: 645

Answers (1)

walkytalky
walkytalky

Reputation: 9543

Without a clearer description of what you mean by "doesn't work", and probably what's going on where you have //code here, it's hard to say.

Basically, you can pass a CGPoint to and from a function or method with the syntax as you have it. It'll be passed by value, so that any changes to position inside the function will not be reflected in the variable passed as argument (b), but should be copied back in the return value (to a).

In the code fragment shown, you don't initialise a or b, so they may contain garbage. And obviously the method body isn't doing much. But otherwise it looks kosher, so the problem is probably elsewhere.

Upvotes: 3

Related Questions