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
import UIKit
 
//--------------------mutable(수정할 수 있는) Array
//배열 선언 방법 3가지
var comment0 = [String]()   //shorthand form
var comment1:Array<String> = []
var comment2:[String= []
 
comment2.append("Anna")
comment2.append("Alex")
 
print(comment2) //["Anna", "Alex"]
 
var comment3 = ["Anna""Alex""Brian""Jack"]
 
comment3 += ["Choi"]
comment3 += ["Jin"]
comment3 += ["Kim"]
 
print(comment3[1])  //Alex
 
comment3[1= "Tim"
print(comment3[1])  //Tim
 
 
 
//--------------------immutable(수정할 수 없는) Array
let comment4 = ["Anna""Alex""Brian""Jack"]
 
//comment4 += ["Choi"]  //이렇게 추가할 경우 오류남
print(comment4) //["Anna", "Alex", "Brian", "Jack"]



'프로그래밍 > Swift | iOS' 카테고리의 다른 글

[Swift3 & iOS10] function  (0) 2017.12.01
[Swift3 & iOS10] 조건문 if,switch  (0) 2017.12.01
[Swift3 & iOS10] 반복문 for,while  (0) 2017.11.30
[Swift3 & iOS10] Dictionary  (0) 2017.11.30
[Swift3 & iOS10] 변수와 상수  (0) 2017.11.30

1
2
3
4
5
6
7
8
9
10
11
12
13
import UIKit
 
//type inference - 타입형을 알아서 판단함
var str = "Hello, playground"
var version = 1.0   //변수(var)
let year = 2015     //상수(let) : 값을 바꿀 수 없음
let handsome = true
 
//타입형을 직접 씀
var str2:String = "Hello, playground"
var version2:Double = 1.0
let year2:Int = 2015
let handsome2:Bool = true



'프로그래밍 > Swift | iOS' 카테고리의 다른 글

[Swift3 & iOS10] function  (0) 2017.12.01
[Swift3 & iOS10] 조건문 if,switch  (0) 2017.12.01
[Swift3 & iOS10] 반복문 for,while  (0) 2017.11.30
[Swift3 & iOS10] Dictionary  (0) 2017.11.30
[Swift3 & iOS10] Array (배열)  (0) 2017.11.30