简体   繁体   中英

“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.

Breaking it in the below manner worked fine for me

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM