Download - 3 swift 컬렉션
Transcript
![Page 1: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/1.jpg)
3. Swift 기초 - 컬렉션 타입 : 배열과 딕셔너리
창원대학교 정보통신공학과 2015. 12.
![Page 2: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/2.jpg)
배열
•같은 타입을 가진 여러 개의 값을 순서대로 저장하는 자료구조
• Objective-C의 경우 NSArray, NSMutableArray라는 클래스가 제공됨
• 스위프트에서 배열은 타입을 명시해야하며, 그렇지 않을 경우 추정을 통해서 타입을 확인함
![Page 3: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/3.jpg)
배열의 생성과 초기화
•배열은 초기화가 필요하다
![Page 4: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/4.jpg)
서로 다른 타입을 가지는 배열
![Page 5: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/5.jpg)
배열의 생성과 초기화
•다양한 초기화 방법이 존재함
![Page 6: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/6.jpg)
비어있는 배열선언과 count
![Page 7: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/7.jpg)
비어있는 배열선언과 count
![Page 8: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/8.jpg)
비어있는 배열선언과 count
![Page 9: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/9.jpg)
배열의 접근 및 수정
![Page 10: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/10.jpg)
배열의 접근 및 수정
![Page 11: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/11.jpg)
배열의 반복문 사용
![Page 12: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/12.jpg)
배열의 반복문 사용
![Page 13: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/13.jpg)
배열값과 인덱스 얻기
enumerate() 메소드를 통해 index, value 튜플을 반환 받을 수 있다
![Page 14: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/14.jpg)
딕셔너리
•딕셔너리는 키(key)/값(value) 쌍으로 구성됨
• key : “Playground”, value : “a place where people can play”
• key : “glossary”, value : “a vocabulary”
• 키를 이용해서 값을 얻어낼 수 있음
![Page 15: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/15.jpg)
Dictionary 생성과 초기화
![Page 16: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/16.jpg)
Dictionary 접근 및 수정
![Page 17: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/17.jpg)
Dictionary 반복문 사용
![Page 18: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/18.jpg)
Dictionary 반복문 사용
![Page 19: 3 swift 컬렉션](https://reader033.vdocuments.pub/reader033/viewer/2022042906/58a9355d1a28ab3f778b5d99/html5/thumbnails/19.jpg)
Dictionary의 내용을 배열로