title: How to write to Google Sheets in Swift
body: <p>I'm trying to write to a Google Sheets document by following <a href="https://developers.google.com/sheets/api/guides/values" rel="noreferrer">this google api</a>, but I'm not having much success. I'm not even sure I'm following the right api, because it says "Appscript" and looks like Swift.</p>
  
  <p>I've been able to read in data from the sheets using:</p>
  
  <pre><code>private let scopes = [kGTLRAuthScopeSheetsSpreadsheets]
  private let service = GTLRSheetsService()
  
  override func viewDidLoad() {
      super.viewDidLoad()
      self.service.authorizer = GIDSignIn.sharedInstance().currentUser.authentication.fetcherAuthorizer()
      getData()
  }
  
  func getData() {
          let spreadsheetId = "1OAbhzY7RlfCEre-I5e-Kcgz16eHz2cGpO9HZKOiizCs" // Portfolio
      let query = GTLRSheetsQuery_SpreadsheetsValuesGet.query(withSpreadsheetId: spreadsheetId, range:range)
      service.executeQuery(query, delegate: self, didFinish: #selector(displayResultWithTicket(ticket:finishedWithObject:error:)))
  }
  </code></pre>
  
  <p>I tried following the section where the api says:</p>
  
  <pre><code>// This code uses the Sheets Advanced Service, but for most use cases
  // the built-in method SpreadsheetApp.getActiveSpreadsheet()
  //     .getRange(range).setValues(values) is more appropriate.
  var values = [
    [
      // Cell values ...
    ]
    // Additional rows ...
  ];
  var valueRange = Sheets.newValueRange();
  valueRange.values = values;
  var result = Sheets.Spreadsheets.Values.update(valueRange, spreadsheetId, range, {
    valueInputOption: valueInputOption
  });
  </code></pre>
  
  <p>But I'm very lost in what SpreadsheetsApp.getActiveSpreadsheet() is coming from. I don't really know what the SpreadsheetsApp or Sheets object/library even is, and it doesn't seem to exist when I try to use it in my code </p>
  
  <p>Being utterly lost on how to do this, I tried:</p>
  
  <pre><code>func writeData() {
      let spreadsheetId = "1OAbhzY7RlfCEre-I5e-Kcgz16eHz2cGpO9HZKOiizCs"
      let range = "A1:E"
      let query = GTLRSheetsQuery_SpreadsheetsValuesGet.query(withSpreadsheetId: spreadsheetId, range:range)
      var values = [[]]
      var valueRange = query.newValueRange()
      valueRange.values = values
      var result = query.values.update(valueRange, spreadsheetId, range, {
          valueInputOption: valueInputOption
      })
  }
  </code></pre>
  
  <p>But, as expected, I get a lot of errors since query does not have a newValueRange method, or a values.update method or anything like that. </p>
  
  <p>Can anyone help me please? I'm very lost</p>