Q:

Why I can't use variable that I defined in viewDidLoad in swift 3

I defined a variable in viewDidLoad But The problem is that I can't use that variable in the same View Controller outside of viewDidLoad.
Here is my code:
class ProfileSettingTableViewController: UITableViewController {

var userAccountMoney = String()

var headerList = ["account\(ProfileSettingTableViewController().userAccountMoney)" , "Help" , "" ]

override func viewDidLoad() {
    super.viewDidLoad()

    let userAccount = profileViewController().userMoney

    let numberFormatter = NumberFormatter()
    numberFormatter.locale = Locale(identifier: "fa")
    numberFormatter.numberStyle = NumberFormatter.Style.decimal
    numberFormatter.string(from: NSNumber(value: userAccount))
    userAccountMoney.append(numberFormatter.string(from: NSNumber(value: userAccount))!)

}

this code compiles, but even if I define for example let a = 1000 I can't reach that outside viewDidLoad

A:

The issue is you cannot access instance property when you initialized another another property outside any method because complier don't know which one initialized the first, so what you need to do is declare headerList simply set the account string only as first object of array and latter changed it with new value.
var userAccountMoney = String()
var headerList = ["account" , "Help" , "" ]

Now in viewDidLoad simply replace the first object with new value.
override func viewDidLoad() {
    super.viewDidLoad()

    let userAccount = profileViewController().userMoney

    let numberFormatter = NumberFormatter()
    numberFormatter.locale = Locale(identifier: "fa")
    numberFormatter.numberStyle = NumberFormatter.Style.decimal
    numberFormatter.string(from: NSNumber(value: userAccount))
    userAccountMoney = numberFormatter.string(from: NSNumber(value: userAccount))!
    self.headerList[0] = "account\(userAccountMoney)"
}

