title: Swift: Using data model class structures in initialization routine in ViewController
body: <p>I am using Xcode 8.3 and Swift 3.0.  This is my first attempt at using Swift after going through the <a href="https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/index.html#//apple_ref/doc/uid/TP40015214-CH2-SW1" rel="nofollow noreferrer">Jump Right In</a> tutorial provided by Apple.</p>
  
  <p>I have a data model file that defines a class:</p>
  
  <pre><code>class Location: NSObject, NSCoding {
  
      //MARK: Properties
  
      var name: String
      var number: Int
      var item: String
      var visited: Bool
      var coords: [Coordinates]
  
      //MARK: Types
  
      struct Coordinates {
          // default values are for a location
          let latitude: Double = 35.0
          let longitude: Double = -120.0
      }
  
      //MARK: Initialization
  
      init(name: String, number: Int, item: String, visited: Bool, coords: [Coordinates]) {
  
          // Initialize stored properties
          self.name = name
          self.number = number
          self.item = item
          self.visited = visited
          self.coords = coords
      }
  }
  </code></pre>
  
  <p>I also have a ViewController that I want to use the data in.  Right now, I'm still writing/learning, so I'm having it load a sample piece of data that I enter by hand:</p>
  
  <pre><code>class ViewController: UIViewController {
  
      //MARK: Properties
      // an array of the locations
      var locations = [Location]()
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          // Load a sample location.
          locations[0] = Location(name: "foo", number: 1, item: "bar", visited: false, coords: [Location.Coordinates(latitude: 36.0, longitude: -121.0)])
          os_log("Locations successfully loaded on map screen.", log: OSLog.default, type: .debug)
      }
  }
  </code></pre>
  
  <p>The problem part is clearly <code>coords: [Location.Coordinates(latitude: 36.0, longitude: -121.0)]</code>, which I added after the code was otherwise functioning.  The error Xcode gives me is:</p>
  
  <blockquote>
    <p>Cannot invoke value of type 'Location.Coordinates.Type' with argument list '(latitude: Double, longitude: Double)'</p>
  </blockquote>
  
  <p>When I search for this error, I find <a href="https://stackoverflow.com/questions/34932917/accessing-struct-from-one-class-to-another">this question</a>, which looks very similar to me.  So, I do as the accepted answer says: </p>
  
  <ul>
  <li><p>I create an instance of the Coordinates type in the Location class (adding <code>var instanceOfCoordinates = Coordinates()</code> after the definition of Coordinates) </p></li>
  <li><p>I also create an instance of the Location class in the ViewController class (adding <code>let instanceOfLocation = Location.self</code> after declaring the locations property)</p></li>
  <li><p>I update the problematic bit of code to <code>coords: [instanceOfLocation.instanceOfCoordinates(latitude: 36.0, longitude: -121.0)]</code></p></li>
  </ul>
  
  <p>I get a different error:</p>
  
  <blockquote>
    <p>Instance member 'instanceOfCoordinates' cannot be used on type 'Location'</p>
  </blockquote>
  
  <p>EDIT: Adding [] around the part of the code after <code>coords:</code> but before the last <code>)</code> doesn't change the errors.</p>
  
  <p>What I want is be able to keep the coordinates as a structure within the location so that they are always together and I can use dot referencing to get the values in the form <code>locations[0].coords[index].latitiude</code> and <code>locations[25].coords[index].longitude</code> and so on.  Eventually this will be used to populate a google map with pins.</p>
  
  <p>I am sure there are a great many subtleties (and not so subtle) of Swift lost on me, but usually searching and tinkering works out, but not this time.</p>
  
  <p>Can someone please demonstrate what I'm doing wrong here?</p>