Problem: I have a set of images, lets say 5. There is an structure that defines an ‘image object’ in the meaning of my context.
Every such image object has this information:
- name, of the image file (ie ‘myImage.png’)
- xOffsetPx
- yOffsetPx
- width
- height
The images are supposed to be shown on very specific positions in an view, so I need to store all this information in some sort of multidimensional associative array (or similar). The name of the image would be the key or ID.
I stumbled upon something like that a month ago in my 1000 pages objective-c book, but can’t find it anymore. Any idea here?
The most simple way would be to just use a dictionary:
You would probably want your attributes to be constants of some kind so that compiler can warn you if you make a spelling error. You could also have a simple data object class with a few properties on it, then set those and add the object directly to the dictionary. There are a number of other ways to solve this problem, depending on your exact requirements, but NSDictionary is the basic collection class in Cocoa for associative arrays.