ios - Replacing multiple characters in swift -


i working on application gets info movies api, api returns genres of movie in special int ids each genre(28 action , 12 adventure). how go changing these ids actual genre names? tried using stringbyreplacingoccurrencesofstring("\(genreids)", withstring: "\(genrenames)") (genreids , genrenames arrays) application crashed.

there no 1 call (at least not know of) replace array of source strings array of replacement strings in 1 go. method stringbyreplacingoccurrencesofstring replaces instances of 1 string string.

you need loop through arrays of genre ids , genre names , call function repeatedly. this:

for (index, genreid in genreids.enumerated() {    let genrename = genrenames[index]    let genreidstring = "\(genreid)"    let movienames =        movienames.stringbyreplacingoccurrencesofstring(genreidstring,           withstring: genrename) } 

(note variable names , function names should start lower-case letters, , class names , type names should start upper-case letters.)


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -