LoginSignup
1
0

More than 5 years have passed since last update.

配列から指定範囲を抜き出した時、ArraySliceになるからArrayにしたい

Posted at

配列から一部の要素を抜き出すと、それは配列ではなくSliceという型になる。そのままだと配列型に渡せず困ることがある。

// これはArray<Int>型
let intArray1: [Int] = [1, 2, 3, 4, 5]
// これはArraySlice<Int>型
let intArraySlice = intArray1[1...3]
// Array<Int>に戻す
let intArray2 = Array(intArraySlice)

めんどくさい・・・

guttari256.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0