0

I create an NSMutableArray and fill it with a bunch coordinates.

I assign the array to the property of another array like this:

draw.shapeCoords = [shapes shapeCoords];

Where draw is a class and shapes is a class and shapeCoords are properties in both of them.

When I get to my drawRect method, the array of coordinates is empty. I'm did a little research and found that the @synthesize does not fully instantiate an NSMutableArray, how then in my draw class (which implements UIView) do I initialize the array? Basically, I need access to the data in the array, how do I get it?

1 Answer 1

2

@synthesize doesn't instantiate an object at all — it just creates a variable (initialized to nil) and accessor methods. You need to actually create the array. In your initWithFrame:, you'll want something like _shapeCoords = [[NSMutableArray alloc] init].

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

6 Comments

When is initiWithFrame called? I don't think it is being called and I am not calling it. How do I get initWithFrame to execute? Thanks.
That didn't work, I was sure it would though. Can you think of any reason why the array would be empty every time I try to grab it?
Just wondering, shouldn't it be self.shapeCoords since _shapeCoords is an accessor, not a setter?
@ChrisLoonam: Either I don't understand what you're saying or you have that backwards.
Maybe I'm wrong, I just thought that using self. is how you're supposed to set properties
|

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.