ios - Display array from a value in the array -


so if have array this:

var myarray = ["bmw", "toyota", "ford", "lamborghini", "ferrari", "lada"] 

i want display value inside array after "ford", bmw, toyota , ford doesn't show up.. how can this?

using swift slice, e.g:

myarray[3...myarray.count - 1] 

output

["lamborghini", "ferrari", "lada"] 

option 1

if don't know index of ford element, find using indexof method:

if let index = myarray.indexof("ford") {     let startindex = index + 1     let endindex = myarray.count - 1     let slice = myarray[startindex...endindex]     let array = array(slice)     print(array)   // prints ["lamborghini", "ferrari", "lada"] } 

option 2

as @leo dabus pointed out, simpler method of getting section want array uses suffixfrom method:

if let index = myarray.indexof("ford") {     let slice = myarray.suffixfrom(index.successor())     let array = array(slice)     print(array)  // prints ["lamborghini", "ferrari", "lada"] } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -