0

So I have this CGPoint vertexLocations[6][6] multidimensional array which has all my vertex locations for 6 horizontal lines and 6 vertical lines. I created vertexLocations in a method. However i need to access it out of my method, but I having a hard time creating it into a global variable. I've tried the following:

@property CGPoint vertexLocations[][];
@property CGPoint vertexLocations[6][6];

But the complier screams at me for both, I also tried having my method return the multidimensional array but every way I tried it screamed at me. Any suggestions would be much appreciated, thanks!

Cris
  • 339
  • 1
  • 3
  • 7
  • possible duplicate of [shared global variables in C](http://stackoverflow.com/questions/3010647/shared-global-variables-in-c) – Carl Veazey Apr 25 '14 at 04:14
  • FYI - defining a property is not at all the same as making it a global variable. – rmaddy Apr 25 '14 at 04:18
  • Really? Its makes it so it can be accessed anywhere in the class. That's all a global variable is, isn't it? – Cris Apr 25 '14 at 04:20
  • If you want a variable to be accessed from anywhere in the instance methods of the class, you make it an instance variable. A property is an instance-level item that typically (but not always) wraps an instance variable. A global variable (probably a file static variable) would not be an instance variable. It would exist at the global scope meaning all instances of the class would share the same exact copy of the data. This variable would be accessible by any code in the .m file. Which do you want? – rmaddy Apr 25 '14 at 04:33
  • I want the variable to be accessed anywhere in the .m file. Thank you for your explanation, cleared some things up. Do you know how I would do that? – Cris Apr 25 '14 at 04:38
  • Declare it as a `static` variable before your `@implementation` block. Again, such a variable will only exist once regardless of how many instances of your class you create. Change it in one method for one instance and the change will be reflected in all instances. – rmaddy Apr 25 '14 at 04:57
  • Awesome, makes perfect sense, thank you – Cris Apr 25 '14 at 05:06

0 Answers0