1. suisuina

    Posted

    suisuina
Changes in title
+Swift 配列の基本
Changes in tags
Changes in body
Source | HTML | Preview
@@ -0,0 +1,72 @@
+配列の基本について記載
+
+
+型指定
+
+```swift
+var ary:Array<Int> = [1,13]
+```
+
+型指定[]での記述
+
+```swift
+var ary:[Int] = [1,2]
+```
+
+複数の型指定
+
+```swift
+var ary:Array<Any> = [1,"anything"]
+```
+
+追加
+
+```swift
+ary.append("add")
+
+```
+
+指定indexに追加
+
+```swift
+ary.insert("add0", atIndex: 0)
+```
+
+index値が1以上3未満の値を置き換える
+
+```swift
+var animal = ["tiger","elephant","dog","cat"]
+animal[1..<3] = ["a","b"]
+print(animal) //"["tiger", "a", "b", "cat"]\n"
+```
+
+index値が1~3の値を置き換える
+
+```swift
+var animal = ["tiger","elephant","dog","cat"]
+animal[1...3] = ["a","b"]
+print(animal) //"["tiger", "a", "b"]\n"
+```
+
+指定indexを削除
+
+```swift
+var animal = ["tiger","elephant","dog","cat"]
+animal.removeAtIndex(2)
+print(animal) // "["tiger", "elephant", "cat"]\n"
+```
+
+コピー
+(配列のコピーは参照渡しではなく、値のコピーになります。)
+
+```swift
+var animal = ["tiger","elephant","dog","cat"]
+var copyArray = animal
+copyArray[0] = "change"
+print(copyArray[0]) // change
+print(animal[0]) //tiger
+```
+
+
+以上
+