title: How do I access my array from my table data source?
body: <p>I am starting my first Cocoa Project. And I have a serious (for me) but maybe easy problem (for you) to solve and I need some direction where to start.</p>
  
  <p>The short description: I have built a class "PortConnection.h" who writes all ports found by an external class (AMSerial.h) into an array when the function -listPorts is called. Here is the code for the PortConnection.h</p>
  
  <pre><code>#import &lt;Cocoa/Cocoa.h&gt;
  #import "AMSerialPortList.h"
  #import "AMSerialPortAdditions.h"
  #import "AMSerialPort.h"
  
  @interface PortConnection : NSObject {
  @private
      AMSerialPort *port;
      NSMutableArray *portArray;
  }
  
  - (void)listDevices;
  
  @property (nonatomic, retain) NSMutableArray *portArray;
  @property (nonatomic, retain) AMSerialPort *port;
  
  @end
  </code></pre>
  
  <p>and following the PortConnection.m</p>
  
  <pre><code>#import "PortConnection.h"
  #import "AMSerialPortList.h"
  #import "AMSerialPortAdditions.h"
  #import "AMSerialPort.h"
  
  @implementation PortConnection
  @synthesize portArray;
  @synthesize port;
  
  - (void)listDevices
  {
      // get an port enumerator
      NSEnumerator *enumerator = [AMSerialPortList portEnumerator];
      AMSerialPort *aPort;
  
      while ((aPort = [enumerator nextObject]))
      {
          // Add Devices to Array
          [portArray addObject:[aPort bsdPath]];
  
      }
  }
  </code></pre>
  
  <p>So far it is perfectly working.
  Now my questions</p>
  
  <p>I have implemented an tableView in the GUI for display the results of the method called above. This file is called "PortTableViewController.h" and is the datasource for my TableView.</p>
  
  <p>Here is the .h file</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  #import "PortConnection.h"
  
  
  @interface PortTableViewController : NSObject &lt;NSTableViewDataSource&gt; {
  @private
      IBOutlet NSTableView *portTableView;    
  }
  
  @property (assign) IBOutlet NSTableView *portTableView;
  
  @end
  </code></pre>
  
  <p>and here is the .m file:</p>
  
  <pre><code>#import "PortTableViewController.h"
  #import "PortConnection.h"
  
  
  @implementation PortTableViewController
  @synthesize portTableView;
  
  #pragma mark -
  #pragma mark TableView Delegates
  
  
  - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView{
      PortConnection *portConnection = [[PortConnection alloc] init];
      [portConnection listDevices];
      return [portConnection.portArray count];
  }
  
  - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
          ??????? I DO NOT HAVE A CLUE HOW TO ACCESS THE ARRAY IN PORTCONNECTION.M CORRECTLY
  }
  
  @end
  </code></pre>
  
  <p>QUESTIONS:</p>
  
  <p>1) When having a look on the TableViewDataSourceDelegates how do I access the filled portArray in the PortConnection.m class correctly. It doesn't seem to work the way I do it.</p>
  
  <p>2) Do I have to create an Object from Portconnection.h every time I want to retrieve Data from it in a tableviewdelegate method?</p>
  
  <p>I am really thankful for every kind of help! I want to learn something.. and I really appreciate your support! Thanks.. for question in order to help me, don't hesitate. I really appreciate it....</p>
  
  <p>Thanks
  Sebastian</p>