IOS/Swift 문법
2. Array
Hoya0415
2016. 5. 18. 22:49
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | //: Playground - noun: a place where people can play import UIKit //mutable array var comment:Array<String>= [] var comment2:[String] = [] comment2.append("Anna") comment2.append("Alex") var comment3 = ["Anna","Alex","Brian","Jack"] comment3 += ["Song"] comment3 += ["jin"] comment3 += ["Kim"] print(comment3[1]) comment3[1] = "Tim" comment3[2...4] = ["Free","Style"] print(comment3) //immutable array let comment4 = ["Anna","Alex","Brian","Jack"] //comment4 += "Song" //var someInts = [Int]() //print("someInts is of type [int[ with \(someInts.count) iteems.") | cs |
배열 풀 닉네임으로 선언을 했을 경우는 변수명 뒤에 :Array[Element]를 써주면 된다
Written in full as : var 변수명:Array<Element>
짧게 배열을 선언 할려면 변수명 뒤에:[Element] 타입을 사용하면 된다.
shorthand [Element]
var 변수명 = [Element]