null - Populating dictionary in Swift -


i've got simple function compiles dictionary 2 others according last. compiler shows no errors, after execution resultdict empty. in debug vars counter, type.1 , tempdict have correct not-nil values.

func compilebasefromcsv(original: [int:[string]], headers: [int:string]) -> [int:[string:[string]]] {     var resultdict = [int:[string:[string]]]()     var tempdict = [string]()     var counter = 0     type in headers {         object in original {             tempdict.append(object.1[type.0])         }         resultdict[counter]?[type.1] = tempdict         counter += 1     }     print(resultdict)     return resultdict } 

what's wrong code? thanks!

for one, never set resultdict[counter], need like:

if resultdict[counter] == nil {   resultdict[counter] = [:] } 

before pushing values it.

but there seem few more issues in code (e.g. should tempdict reset?). use debugger step through code , @ values , check how change (and whether matches desire).


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -