suchen

Heim  >  Fragen und Antworten  >  Hauptteil

ios - Swift中数组如何像OC中一样取subarrayWithRange

Swift中数组如何像OC中一样取subarrayWithRange获得子数组呢?

巴扎黑巴扎黑2771 Tage vor607

Antworte allen(2)Ich werde antworten

  • 高洛峰

    高洛峰2017-04-17 16:37:39

    let a = [1,2,3,4,5,6]
    let b = a[2...5]
    //b = [3,4,5,6]

    如上

    Antwort
    0
  • 怪我咯

    怪我咯2017-04-17 16:37:39

    上面获得的是ArraySlice 需要再用Array来包一层

    let a = [1,2,3,4,5,6]
    
    let b = a[0...1]
    
    //b is type of ArraySlice
    
    let b= Array(a[0...1])
    //b is array 
    

    Antwort
    0
  • StornierenAntwort