1) [String:Any] is not array, it is Dictionary<String, Any>. I think you mean that myArray have type [[String:Any]]
2) Array and Dictionary types passes by value in swift, not by reference. So tempValue is different instance with same values
You can try this code:
(self.myArray[0]["values"] as? [AnyObject])?.append("hello") // - wrong!!
UPDATE:
Thought this answer marked as correct, I found issue in it. Seems like result of (self.myArray[0]["values"] as! [AnyObject]) (even with force unwrapping) will be immutable array. So you can not use append method in it. You need overwrite whole key with new array:
if var tempValue = self.myArray[0]["values"] as? [AnyObject] {
tempValue.append("hello")
self.myArray[0]["values"] = tempValue
}
UPDATE 2:
About passing data between view controllers. Let me show you one of my solutions for modify settings of firstViewController from secondViewController. First I define settings class:
class ControllerSettings: NSObject {
var userInfo = Dictionary<String, AnyObject?>()
var myArray = [AnyObject]()
override var description: String {return "- userInfo: \(userInfo)\n - myArray: \(myArray)"}
}
firstViewController will use settings property for save it settings, and pass reference to this property to child secondViewController; after secondViewController will modify it and dismiss, firstViewController will able to check changes in viewWillAppear method
class FirstViewController: UIViewController {
var settings = ControllerSettings()
//...
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
print("here is actual settings:\n\(settings)")
//...
}
//...
func showSecondController() {
let secondViewController = SecondViewController()
secondViewController.firstViewControllerSettings = settings
presentViewController(secondViewController, animated: true, completion: nil)
}
}
class SecondViewController: UIViewController {
var firstViewControllerSettings: ControllerSettings?
//...
func mutateSettingsAndDismiss() {
firstViewControllerSettings?.myArray.append("NewSetting")
dismissViewControllerAnimated(true, completion: nil)
}
}
[String:Any]this is not an array but dictionary