Quick question on using arrays with CGFloats
Hi all,
I'm very new to Obj-C / Cocoa, and need a little guidance on the usage of arrays, if anyone would be so kind...
I am basically trying to create a bunch of CGPoint objects from coordinate values stored within a couple of arrays (each storing separate x and y values). I understand that the CGPointMake() function requires CGFloats, but I can't seem to work out how to get them in and out of the array!
How should I be doing this??
Any help would be gratefully appreciated!!
Cheers!
D.
I'm very new to Obj-C / Cocoa, and need a little guidance on the usage of arrays, if anyone would be so kind...
I am basically trying to create a bunch of CGPoint objects from coordinate values stored within a couple of arrays (each storing separate x and y values). I understand that the CGPointMake() function requires CGFloats, but I can't seem to work out how to get them in and out of the array!
How should I be doing this??
Any help would be gratefully appreciated!!
Cheers!
D.
Errr... what?
I really don't understand what you're asking so I'll just throw out some possibilities to the only way I can interpret your question...
CGFloat floatArray[] = {...};
CGFloat aFloat = floatArray[someIndex];
--
NSArray * someArrayOfNSNumbersContainingFloats = ...;
CGFloat aFloat = [[someArrayOfNSNumbersContainingFloats objectAtIndex:index] floatValue];
I really don't understand what you're asking so I'll just throw out some possibilities to the only way I can interpret your question...
CGFloat floatArray[] = {...};
CGFloat aFloat = floatArray[someIndex];
--
NSArray * someArrayOfNSNumbersContainingFloats = ...;
CGFloat aFloat = [[someArrayOfNSNumbersContainingFloats objectAtIndex:index] floatValue];
[I'm guessing] He's probably looking for NSValue:
Code:
[myArray addObject:[NSValue valueWithCGPoint:CGPointMake(x, y)]];
Thanks for this!! Sorry about my garbled question. It was brought about mainly by my apparent lack of understanding of C arrays. I was thinking I had to work with NSArrays. Didn't realise that creating C arrays was so simple. I have since edumacated myself!!
Thanks again!
D.
Thanks again!
D.
AJ - I opted for using NSNumber, which is, I think, a subclass of NSValue, but was told that I was doing things too inefficiently. I am now trying to do it another way (probably just using normal C arrays).
Basically, I'm simply trying to provide a UIImageView object (a sprite, of sorts...) with a list of x and y coordinates from which to use as the center positions for a bunch of new sub-UIImageViews (ie, sub-views of the "sprite" object).
Thanks for your help!
Dunc.
Basically, I'm simply trying to provide a UIImageView object (a sprite, of sorts...) with a list of x and y coordinates from which to use as the center positions for a bunch of new sub-UIImageViews (ie, sub-views of the "sprite" object).
Thanks for your help!
Dunc.
Yep, nothing wrong with good 'ol C arrays.
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
Quick Newbie Question | Wayrath | 1 | 3,159 |
Apr 17, 2010 07:39 PM Last Post: smasher |
|
Obj C object level arrays question | Elphaba | 3 | 3,410 |
Aug 5, 2009 12:35 PM Last Post: Elphaba |