Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- NSPredicates
- Swift LinkedList
- dateFormatter
- 트레일링 클로저
- Swift
- LightWeight Migration
- Java
- NSManagedObject SubClass
- Persistent store Coordinator
- CoreData
- 다익스트라 이해
- Raw value and Associated value
- 1009번
- persistentStoreCoordinator
- CoreData Filter
- expensive operation
- codability
- leetcode #01
- NSSortDescriptor
- Associated Value
- 일급 객체
- 2022 부스트캠프
- Clean swift
- Swift 고차함수
- iOS Static Library
- 스위프트 클로저
- CoreData Stack
- Swift closure
- CoreData Concurrency
- iOS Static Library 사용하는방법
Archives
- Today
- Total
하루를살자
Swift - Optionals 본문
Usage
- The Optional is used to declare a variable but don't want to set a default value
- It is used when using nil to represent an unset state
- when using a variable to reference data that can actually be nil
Two ways to use Optionals
1. Implicitly unwrapped optional
2. Optional
// Implicitly Unwrapped optionals
// It can contain nil
// Xcode doesn't alert the user
// It doesn't need to be unwrapped
var a:String! = nill
//Optional
//It can contain nill
//Xcode warns the user
//Need to unwrap the variable to get value
var b:String? = nill
// Optional Binding
if let a = b {
var x = a + 1
print(x)
}
The Optional Binding checks whether the variable b is nil or not, and if it isn't, it assigns its value into Constant "a". So when using inside of If loop, it is not necessary to unwrap variable "a" using "!".
'Swift' 카테고리의 다른 글
Swift 고차함수 (0) | 2022.02.05 |
---|---|
Swift - Collection Types (0) | 2022.01.01 |
Swift - Enum (0) | 2021.12.31 |
SwiftUI Architecture - MVVM (Model, View, and ViewModel) (0) | 2021.12.20 |
Swift Basics - Playground(Xcode), Data type, Function (0) | 2021.12.17 |
Comments