title: declaring double arrays in objective-c
body: <p>My map object has a set of coordinates. It doesn't always have the same number of coordinates.
  In java I'd just declare the object as <code>Double[] xpoints</code> and would set it's size when instantiating a map like this: <code>xpoints = new double[npoints]</code>;</p>
  
  <p>How can I do this with objective-c?</p>
  
  <p>I tried doing this: <code>@property(nonatomic) double * xpoints;</code> but somehow all of it's values turn to 0 when I print it with NSLog. </p>
  
  <p>Map's init:</p>
  
  <pre><code>-(id)initWithXpoints:(double[]) xpointss Ypoints:(double[]) ypointss Npoints:(int)npointss
  {
      self = [super init];
      if (self)
      {
          self.xpoints = xpointss;
          self.ypoints = ypointss;
          self.npoints = npointss;
      }
      return self;
  }
  </code></pre>
  
  <p>Something weird happens though. The values are changed to zero when I print xpoints[0] from the object that created the map. The first time I print it it works. The second time it just prints zero.</p>
  
  <p>I think it happens because xpointss sent to init is removed from the memory. How can I "instantiate" the xpoints property if it's a pointer? </p>
  
  <p>Is there a better way to do this?</p>
  
  <p>added: I tried creating a temporary xpoints like this:</p>
  
  <pre><code>double tempxpoints[npointss];
  double tempypoints[npointss];
  for (int i = 0; i &lt; npointss; i++)
  {
      tempxpoints[i] = xpointss[i];
      tempypoints[i] = ypointss[i];
  }
  self.xpoints = tempxpoints;
  self.ypoints = tempypoints;
  </code></pre>
  
  <p>But it still didn't work. </p>
  
  <p>Edit: Thanks for all the answers. This ended up being my final Init code:</p>
  
  <pre><code>-(id)initWithXpoints:(double[]) xpointss Ypoints:(double[]) ypointss Npoints:(int)npointss
  {
      self = [super init];
      if (self)
      {
           _xpoints = [[NSMutableArray alloc] init];
           _ypoints = [[NSMutableArray alloc] init];
           for (int i = 0; i &lt; npointss; i++)
           {
               NSNumber *tempx = [NSNumber numberWithDouble:xpointss[i]];
               NSNumber *tempy = [NSNumber numberWithDouble:ypointss[i]];
               [_xpoints addObject:tempx];
               [_ypoints addObject:tempy];
           }
           _npoints = npointss;
      }
      return self;
  }
  </code></pre>