• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Accessor method for array of floats
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessor method for array of floats


  • Subject: Re: Accessor method for array of floats
  • From: Dylan Adams <email@hidden>
  • Date: Sat, 19 Jul 2003 15:28:05 -0500

Johan Kool wrote:
But how do I create an accessor for my array of floats? I want to store that entire
array of floats in a variable of my model class, and have the entire array returned
when I use the appropiate accessor method. But the problem is that I don't know
how to allocate the memory for the variable in my model class so it is big enough
to hold the entire content of my array. What should I do?

You haven't specificed what sort of array you're using. If you're using an NSArray, you need to wrap your floats with NSNumber objects. If that's the case, your accessors might look something like this, given an instance variable `floats' of type NSMutableArray *:

-(NSArray *)floats
{
return ([NSArray arrayWithArray: floats]);
}

-(void)setFloats: (NSArray *)newFloats
{
floats = [newFloats mutableCopyWithZone: nil];
}

-(void)addFloat: (float) aFloat
{
[floats addObject: [NSNumber numberWithFloat: aFloat]];
}
-(float)floatAtIndex: (int) index
{
NSNumber *float;

float = [floats objectAtIndex: index];

return ([float floatValue]);
}

If you're using standard C arrays, you need to do the usual dynamic array stuff using malloc/realloc, keeping track of the size of the array and growing it on demand. I'm sure you can find something on google about this.

dylan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Accessor method for array of floats (From: Johan Kool <email@hidden>)

  • Prev by Date: Accessor method for array of floats
  • Next by Date: SplitView
  • Previous by thread: Accessor method for array of floats
  • Next by thread: Re: Accessor method for array of floats
  • Index(es):
    • Date
    • Thread