Ankit Kumar Gupta Ankit Kumar Gupta - 15 days ago 5
iOS Question

"Expression was too complex to be solved in reasonable time" while adding data to dictionary in swift 3, works fine in swift 2.3

let parameters : [String : AnyObject] = [
"address" : txtAddress.text ?? "",
"person_name" : txtAuthorName.text ?? "",
"person_image" : imgUrl ?? "",
"book_title" : txtBookTitle.text ?? "",
"dedicated_to" : txtDedicatedTo.text ?? "" ,
"person_about" : txtAboutTheAuthor.text ?? "",
"is_published" : false,
"recipes" : recipeArr ?? ""]


This is the code for adding data to dictionary. Works fine on Swift2.3.

Swift 3 Compiler says to break the expression to sub-expressions.

Kindly suggest an apt solution.

Answer

Breaking it in the below manner worked fine for me

var dictionary =  [String: Any]()
   dictionary["key1"] = value1
   dictionary["key2"] = value2
   //...
Comments