본문 바로가기
공부/iOS

iOS 프로그래밍 2주차

by Electrohyun 2025. 9. 9.

강의 목표

 

1. Mac 사용법과 Xcode로 앱 실행해보기
2. Swift 문법 (자료형, print, 변수, 상수, tuple)

 

메모용 맥 단축키

 


 

맥북 앱스토어

 

신기한 플래피버드

 


문서

 

- Swift 변경 사항 정리

https://docs.swift.org/swift-book/documentation/the-swift-programming-language/revisionhistory/

 

- Swift 언어 스타일 가이드

https://github.com/swift-kr/swift-style-guide-raywenderlich/blob/master/ko_style_guide.md

 

swift-style-guide-raywenderlich/ko_style_guide.md at master · swift-kr/swift-style-guide-raywenderlich

The official Swift style guide for raywenderlich.com. - swift-kr/swift-style-guide-raywenderlich

github.com

 

온라인 디버거

 

https://www.onlinegdb.com/online_swift_compiler

 

Online Swift Compiler - online editor

OnlineGDB is online IDE with swift compiler. Quick and easy way to run swift scripts online.

www.onlinegdb.com

 

https://swiftfiddle.com/

 

Swift Online Playground

SwiftFiddle is an online playground for creating, sharing and embedding Swift fiddles (little Swift programs that run directly in your browser).

swiftfiddle.com

 


 

맥으로 Hello, playGround 출력하기

 

왜 오류가 날까?

 

이건 왜 살짝 다른 빨간 동그라미가 나올까? (클릭해보기)

 

다양한 값 대입 방법...

// 1번 방법

var x : Int
x = 10
print(x)

// 2번 방법

var x = 10
print(x)

 

+ Swift의 기본 자료형은 구조체(struct)로 이루어져 있다!

 

다양한 print 사용 예시들...

 

print 맛보기

print 함수 사용법 예시 (코드 출처: Smile Han 한성현 교수님)

 

type과 size 알아보기

var x = 10

// https://developer.apple.com/documentation/swift/type(of:)
print(type(of:x)) // 실행결과: Int

//https://developer.apple.com/documentation/swift/memorylayout/size(ofvalue:)
let s = MemoryLayout.size(ofValue: x) // 실행결과: 8
let t = MemoryLayout<Int>.size // 실행결과: 8

print(s, t)

+ 정수도 소수도 8바이트로 표현된다.

+ Int8, Int16, Int32, ... 등 다양한 크기의 데이터 타입이 존재하지만, 그대로 Int 쓰는 것을 권장한다고 한다.

 

 

+ Float, Double: 소수점 있는 수를 작성할 경우 기본이 Double임

+ Bool: 초깃값이 true이다!! (: Bool은 대부분 생략)

+ Character: 타입 지정을 생략할 수는 있으나, 초깃값은 작은 따옴표가 아니라 큰 따옴표로 주어야함. 그러지 않을 경우 String 취급

+ var, let: var는 변수, let은 상수! let 선언하고 나서 값 할당 가능함(단 한 번!)

 

swift에서는 var보다 let을 쓰는게 좋은 이유?

1. 값의 불변성(Immutability) -> let을 쓰면 값이 바뀌지 않는다는 것을 보장하므로 코드 안정성 높아짐.

2. 안전한 코드 & 버그 예방 -> 변수의 경우 어디서든 값이 변할 수 있으므로 예기치 못한 버그 발생할 수 있음.

3. 컴파일러 최적화 -> 컴파일러가 값이 변하지 않는다는 사실을 알 수 있다.

'공부 > iOS' 카테고리의 다른 글

iOS 프로그래밍 7주차  (0) 2025.10.14
iOS 프로그래밍 5주차  (0) 2025.09.30
iOS 프로그래밍 4주차  (0) 2025.09.23
iOS 프로그래밍 3주차  (0) 2025.09.16
iOS 프로그래밍 1주차  (0) 2025.09.02