Q:

Modifying struct instance using call to name in function parameter

I am attempting to use Parse to call up some variables and put them into a struct that is already initialized. The calling of the variables is happening smoothly and the data is available, but the inputing of the class into the function is not happening. 
'unit' is a struct that has the name, hp, attack, etc. variables contained within it. 
Is it not possible to pass along an instance of a struct and modify it's values like this? It would save me a lot of copy-pasting code to do it this way. 
Thanks for your help!
func fetchStats(name: String, inout nameOfClass: unit) {
var unitStatArray = []
let query = PFQuery(className: "UnitStats")
query.whereKey("name", equalTo: name)

query.findObjectsInBackgroundWithBlock{(objects:[PFObject]?, error: NSError?)->Void in

  if (error == nil && objects != nil){ unitStatArray = objects! }
  nameOfClass.name = "\(unitStatArray[0].objectForKey("name")!)"
  print("class name is \(nameOfClass.name)")
  print("cannon name is \(cannon.name)")
  nameOfClass.hitPoints =      unitStatArray[0].objectForKey("hitPoints") as! Double
  nameOfClass.hitPointsMax =   unitStatArray[0].objectForKey("hitPointsMax") as! Double
  nameOfClass.attack =         unitStatArray[0].objectForKey("attack") as! Double
  nameOfClass.defense =        unitStatArray[0].objectForKey("defense") as! Double
  nameOfClass.rangedAttack =   unitStatArray[0].objectForKey("rangedAttack") as! Double
  nameOfClass.rangedDefense =  unitStatArray[0].objectForKey("rangedDefense") as! Double
  nameOfClass.cost =           unitStatArray[0].objectForKey("cost") as! Int

}

}

fetchStats("3-inch Ordnance Rifle", nameOfClass: &cannon)

A:

This is an attempt to explain what I had in mind when writing my comment above.
Because there's an asynchronous call to findObjectsInBackgroundWithBlock, the inout won't help you here. The idea is to add a callback fetched like this:
func fetchStats(name: String, var nameOfClass: unit, fetched: unit -> ()) {
  // your code as above
  query.findObjectsInBackgroundWithBlock {
    // your code as above plus the following statement:
    fetched(nameOfClass)
  }
}

This can be called with
fetchStats("3-inch Ordnance Rifle", nameOfClass: cannon) { newNameOfClass in
  nameOfClass = newNameOfClass
}

(all of this code has not been tested)
The point is that you understand that your code is asynchronous (I know, I'm repeating myself). After you have called fetchStats you don't know when the callback (here: the assignment nameOfClass = newNameOfClass) will be executed. You cannot assume the assignment has been done after fetchStats has returned.
So whatever you need to do with the changed nameOfClass: the corresponding statements must go into the callback:
fetchStats("3-inch Ordnance Rifle", nameOfClass: cannon) { newNameOfClass in
  // do whatever you want with the received newNameOfClass
}

Hope this helps.

