-2
var KEB_Hana: [String: Any] = [:]

override func viewDidLoad() {
    super.viewDidLoad()
    perform(#selector(LaunchingViewController.showLaunch), with: nil, afterDelay: 2)
    // Do any additional setup after loading the view.
    indi.startAnimating()
    //        if let value = UserDefaults.standard.string(forKey: "introMessage") {
    //            introMessage.text = UserDefaults.standard.string(forKey: "introMessage")
    //        }

    if let value = UserDefaults.standard.object(forKey: "userBeacon") {
        KEB_Hana = UserDefaults.standard.object(forKey: "userBeacon") as! [String : Any]
        print(KEB_Hana)

        var Edit_Hana = "Beacon0 : " + KEB_Hana["beacon0"] + "Beacon1 : " + KEB_Hana["beacon1"] + "Beacon2 : " + KEB_Hana["beacon2"] + "Beacon3 : " + KEB_Hana["beacon3"]

        introMessage.text = Edit_Hana
    }
}

Why top code is not working? It represent "Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expression"

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • You need to unwrap and cast the subscripts: `var Edit_Hana = "Beacon0 : " + (KEB_Hana["beacon0"] as! String) ...` and so on for all the other subscripts. (If they are not strings, you cannot "add" them in this way at all, so I assume they are strings.) – matt Mar 28 '17 at 03:21

1 Answers1

0

The compiler gave up trying to guess what type Edit_Hana was. Assuming that the values for these keys are string:

let Edit_Hana = ["beacon0", "beacon1", "beacon2", "beacon3"]
    .map { "\($0) : \(KEB_Hana[$0] ?? "n/a")" }
    .joined(separator: ". ")

If you want to be careless, you can use string interpolation:

let Edit_Hana = "Beacon0 : \(KEB_Hana["beacon0"]!). Beacon1 : \(KEB_Hana["beacon1"]!). Beacon2 : \(KEB_Hana["beacon2"]!). Beacon3 : \(KEB_Hana["beacon3"]!)"
Code Different
  • 90,614
  • 16
  • 144
  • 163