본문 바로가기

Programming/Swift13

Adrenalist does not collect any personal information Adrenalist the workout app does not collect any kind of personal information. 2021. 5. 6.
[Swift] Optional Unwrapping과 Nil Coalescing Optional Unwrapping방법에는 다음과 같은 것들이 있다. 1. Forced Unwrapping 2. Optional Binding (if let, guard 방법) 1. Forced Unwrapping 이 방법은 가장 간단하게 옵셔널의 값을 추출하는 방법이다. 그러나 가장 위험한 방법이기도 하다. Run Time 오류가 일어날수 있기 때문이다. 그렇기에 왠만하면 사용하지 않는 것이 옳다. var myNumber: Int? = 1 print(myNumber) // optional(1) print(myNumber!) // 1 //Forced Unwrapping 방법 2. Optional Binding 이 방법은 if let이나 guard를 사용하여서 해당 값이 nil인지 아닌지를 판별하여서 옵셔.. 2020. 10. 30.
[Swift] Struct vs. Class 언제 사용? Struct를 써야할때 1. 두 Object를 같다, 다르다 로 비교해야 하는 경우 2. Copy된 각 객체들이 독립적인 상태를 가져야하는 경우 3. 코드에서 Object의 데이터를 여러 thread 걸쳐 사용할 경우 Class를 써야할때 1. 두 Object의 instance 자체가 같음을 확인해야 할때 2. 하나의 객체가 필요하고, 여러대상에 의해 접근되고 변경이 필요한 경우 2020. 10. 22.
[Swift] struct와 class struct - instance는 value type이다. - 정의 struct 구조체 이름{ property and method } ex) struct info { var name: String var height: Int } var myInfo1: Info = Info(name: "Kim", height: 100) myInfo1.name = "Koon" //변경 가능 myInfo1.height = 0 // 변경 가능 let myInfo2: Info = Info(name: "Park", height: 110) myInfo2.name = "Soon" //변경 불가 myInfo2.height = 10 //변경 불가 class - instance는 reference type이다. -정의 class 클래스 이.. 2020. 10. 18.