Quick question on using arrays with CGFloats

Apprentice
Posts: 12
Joined: 2008.11
Post: #1
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.
Quote this message in a reply
⌘-R in Chief
Posts: 1,265
Joined: 2002.05
Post: #2
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];
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #3
[I'm guessing] He's probably looking for NSValue:

Code:
[myArray addObject:[NSValue valueWithCGPoint:CGPointMake(x, y)]];
Quote this message in a reply
Apprentice
Posts: 12
Joined: 2008.11
Post: #4
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.
Quote this message in a reply
Apprentice
Posts: 12
Joined: 2008.11
Post: #5
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.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #6
Yep, nothing wrong with good 'ol C arrays.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Quick Newbie Question Wayrath 1 2,279 Apr 17, 2010 07:39 PM
Last Post: smasher
  Obj C object level arrays question Elphaba 3 2,407 Aug 5, 2009 12:35 PM
Last Post: Elphaba