0

How would I save an Instance so that I could use it in another method? This is the code I have:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    CGPoint     touchedStart;

    // find position of the touch
    touchedStart = [[touches anyObject] locationInView:self];

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    CGPoint     touchedEnd;

    // find position of the touch
    touchedEnd = [[touches anyObject] locationInView:self];

}

I want to be able to use the touchedStart variable in the touchesEnded method. How would I do this?

1 Answer 1

1

Just make it a member variable in the class itself - then the other method will be able to access it.

Sign up to request clarification or add additional context in comments.

2 Comments

@Joshua - It's a variable that is a member of the class (also called an instance variable) as opposed to a "local variable" which is what you have now.
Yes, I know what you mean know I just got a bit confused. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.