Download - Swft 3 for C Programmers : data type
![Page 1: Swft 3 for C Programmers : data type](https://reader036.vdocuments.mx/reader036/viewer/2022092622/5878bb941a28ab724c8b7823/html5/thumbnails/1.jpg)
Swift 3 : Data Types
군산대학교 컴퓨터정보통신공학부 컴퓨터정보공학전공
남 광 우
Swift 3 Tour and Language Guide by Apple꼼꼼한재은씨의 Swift 2 프로그래밍
![Page 2: Swft 3 for C Programmers : data type](https://reader036.vdocuments.mx/reader036/viewer/2022092622/5878bb941a28ab724c8b7823/html5/thumbnails/2.jpg)
Data Type 개요
• Swift에서모든데이터타입은객체
• Int , float 등모든 type이객체• C에서의 int는 atomic type• Java에서는 int Type과 Integer(객체)로구분사용
• 그래서..• 3.distanceTo( 5) : (O)• Int.max : (O)
![Page 3: Swft 3 for C Programmers : data type](https://reader036.vdocuments.mx/reader036/viewer/2022092622/5878bb941a28ab724c8b7823/html5/thumbnails/3.jpg)
Simple Values•변수와상수의선언
•타입의추정
var myVariable = 42 // 변수myVariable = 50
let myConstant = 42 // 상수
let implicitInteger = 70let implicitDouble = 70.0let explicitDouble: Double = 70
![Page 4: Swft 3 for C Programmers : data type](https://reader036.vdocuments.mx/reader036/viewer/2022092622/5878bb941a28ab724c8b7823/html5/thumbnails/4.jpg)
Simple Values•서로다른타입값의변환
•변수상수의이름은한글한자도가능
let label = "The width is "let width = 94let widthLabel = label + String(width)
var한글변수 = 3let ㅎㄱㅂㅅ = 5.3
![Page 5: Swft 3 for C Programmers : data type](https://reader036.vdocuments.mx/reader036/viewer/2022092622/5878bb941a28ab724c8b7823/html5/thumbnails/5.jpg)
기본 자료형
• Int• Int8, Int16, Int32, Int64
• Uint• UInt8, UInt16, UInt32, UInt64
• Double & Float• Bool• String• Character
![Page 6: Swft 3 for C Programmers : data type](https://reader036.vdocuments.mx/reader036/viewer/2022092622/5878bb941a28ab724c8b7823/html5/thumbnails/6.jpg)
기본 자료형
•자료형의선언과사용의세가지방법
// firstvar day = 7
// secondvar day : Intday = 7
// thirdvar day : Int = 7
// 다음은 error!!!!var day day = 7
![Page 7: Swft 3 for C Programmers : data type](https://reader036.vdocuments.mx/reader036/viewer/2022092622/5878bb941a28ab724c8b7823/html5/thumbnails/7.jpg)
닫힌 범위 연산자
•범위값을나타내는연산
• 1…5 : 1, 2, 3, 4, 5
• 1..<5 : 1, 2, 3, 4
• for 문에서의사용• hello 100번 print 하기
for i in 1…100{
print( “Hello” )}
![Page 8: Swft 3 for C Programmers : data type](https://reader036.vdocuments.mx/reader036/viewer/2022092622/5878bb941a28ab724c8b7823/html5/thumbnails/8.jpg)
문자열 template
•변수,상수값을대입하기위한 template• \ (이스케이프) 문자의사용
• hello world 1..<100 까지번호와함께찍기
let apples = 3let oranges = 5let appleSummary = "I have \(apples) apples."let fruitSummary = "I have \(apples + oranges) pieces of fruit.
![Page 9: Swft 3 for C Programmers : data type](https://reader036.vdocuments.mx/reader036/viewer/2022092622/5878bb941a28ab724c8b7823/html5/thumbnails/9.jpg)
Type Aliases
• Type 선언을할수있음
•객체메소드그대로사용가능
typealias AudioSample = UInt16
var maxAmplitudeFound = AudioSample.min// maxAmplitudeFound is now 0
![Page 10: Swft 3 for C Programmers : data type](https://reader036.vdocuments.mx/reader036/viewer/2022092622/5878bb941a28ab724c8b7823/html5/thumbnails/10.jpg)
Tuple• Tuple
• 다수개의쌍으로표현되는데이터모음타입• return 타입으로사용가능
• 선언
•사용예
let http404Error = (404, "Not Found")// http404Error is of type (Int, String), and equals (404, "Not Found")
let (statusCode, statusMessage) = http404Errorprint("The status code is \(statusCode)")// Prints "The status code is 404"print("The status message is \(statusMessage)")// Prints "The status message is Not Found"
![Page 11: Swft 3 for C Programmers : data type](https://reader036.vdocuments.mx/reader036/viewer/2022092622/5878bb941a28ab724c8b7823/html5/thumbnails/11.jpg)
Tuple• Tuple에서의 _
• Tuple에서의 individual element name
let (justTheStatusCode, _) = http404Errorprint("The status code is \(justTheStatusCode)")// Prints "The status code is 404"
let http200Status = (statusCode: 200, description: "OK")
print("The status code is \(http200Status.statusCode)")// Prints "The status code is 200“
print("The status message is \(http200Status.description)")// Prints "The status message is OK"
![Page 12: Swft 3 for C Programmers : data type](https://reader036.vdocuments.mx/reader036/viewer/2022092622/5878bb941a28ab724c8b7823/html5/thumbnails/12.jpg)
Tuple• Tuple에서의 Index 사용
let http200Status = (statusCode: 200, description: "OK")
print("The status code is \(http404Error.0)")// Prints "The status code is 404"print("The status message is \(http404Error.1)")// Prints "The status message is Not Found"