'IOS/Swift 문법'에 해당되는 글 12건

  1. 2016.05.18 2. Array
  2. 2016.05.18 1. 상수와 변수

2. Array

IOS/Swift 문법 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]


'IOS > Swift 문법' 카테고리의 다른 글

6. Functions  (0) 2016.05.20
5. Conditional Statements  (0) 2016.05.20
4. Control Flow  (0) 2016.05.20
3. Dictionary  (0) 2016.05.19
1. 상수와 변수  (0) 2016.05.18
Posted by Hoya0415
,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//: Playground - noun: a place where people can play
import UIKit
 
//type inference
 
var str = "Hello, playground"
 
var version = 1.0
 
let year = 2015
 
let handsome = true
 
 
 
var str2:String = "Hello, playground"
 
var version2:Double = 1.0
 
let year2:Int = 2015
 
let handsome2:Bool = true
cs


type inference 기능으로 인해 명시적으로 변수 타입을 선언하지 않아도 된다.

var 변수명 = 값 :

상수를 선언 할 경우에는 let이라는 키워드를 이용하면 된다

let 변수명 = 값;

명시적으로 변수를 선언이 가능한데 변수명 뒤에 자료형 값을 써주면 된다.

var 변수명:자료형 = 값


'IOS > Swift 문법' 카테고리의 다른 글

6. Functions  (0) 2016.05.20
5. Conditional Statements  (0) 2016.05.20
4. Control Flow  (0) 2016.05.20
3. Dictionary  (0) 2016.05.19
2. Array  (0) 2016.05.18
Posted by Hoya0415
,