arrays - How to transform this statement for better performance -


i have bad performance while building (indexing takes 5 - 7 minutes) since added following lines code.

var valuestopasstodetailviewcontroller = [[string:[string: any]]]() var dict = [string:[string: any]]() dict = [title as! string:["title":title as! string, "valued":postvalue["value"] ?? "", "valued":postvalue["value"] ?? "","valued":postvalue["value"] ?? "","valued": postvalue["value"] ?? "","valued": postvalue["value"] ?? "","valued":postvalue["value"] ?? "","valued":postvalue["value"] ?? "" ,"valued": postvalue["value"] ?? "", "valued": postvalue["value"] ?? ""]] self.valuestopasstodetailviewcontroller.append(dict) 

please have in mind valued replacement key of course different key values , value replacement same 1 above.

please me this. every respond.

(apart being bad code practice) write code swift compiler processes badly, due lot of nesting of literals. (happens in other piece of code.) simpler solution:

as repeatingly using same value:

let nonnullvalue = postvalue["value"] ?? ""  dict = [title as! string : ["title":title,                             "valued": nonnullvalue,                             "valued": nonnullvalue,                             "valued": nonnullvalue,                             "valued": nonnullvalue,                             "valued": nonnullvalue,                             "valued": nonnullvalue,                             "valued": nonnullvalue ,                             "valued": nonnullvalue,                             "valued": nonnullvalue]] 

will job.

if allowed, coding notes:

  • use var repeating values, doing not makes compiler happy, in general faster (especially if use a.b.c.d() produce call/return.. )

  • do not pass generic structures between controls, when read/downloaded, create class/struct , pass them around.

  • is better add dict dynamically, , easy if have read data example disk/network.

hope can help.

another suggestion:

pass typealias in way:

typealias dict = [[string:[string: any]]]

so can write:

    var valuestopasstodetailviewcontroller2 = dict() 

counter-test:

    var valuestopasstodetailviewcontroller = [[string:[string: any]]]()     var valuestopasstodetailviewcontroller2 = dict()      valuestopasstodetailviewcontroller2 = valuestopasstodetailviewcontroller 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -