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
Post a Comment