Swift: Get multiple array values like "x" -


for example, have array var myarray = ['player_static.png', 'player_run0.png', 'player_run1.png', 'player_run2.png', 'player_jump0.png', 'player_jump1.png']

is there simple way "player_runx.png" images?

you can use filter elements hasprefix("player_run"):

let myarray = ["player_static.png", "player_run0.png", "player_run1.png", "player_run2.png", "player_jump0.png", "player_jump1.png"]  let playerruns = myarray.filter{$0.hasprefix("player_run")} print(playerruns)  //["player_run0.png", "player_run1.png", "player_run2.png"] 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -