전체 글
-
WWDC2020 - Unsafe Swift앱등이에게 살충제를 뿌린다./Swift 2021. 5. 14. 18:41
Unsafe Swift Swift에서 제공하는 많은 타입, 프로토콜, 프로퍼티등 그 중 Unsafe라는 접두어를 가진 것들이 있다. 무엇이 다른 것일까? 수행하는 기능, 인터페이스에서 큰 차이점을 가지지는 않는다. Invalid Input을 처리하는 과정에서 차이점을 가진다. 대부분의 Operator가 Input을 완전히 Validation한다. (Swift가 Safe한 Programming Language인 이유) 그래서 우리는 쉽게 에러를 리포트받고 수정할 수 있다. Example Optional을 예로 들어보자. let value: Int? = nil print(value!) // Fatal error: Unexpectedly found nil while unwrapping an Optional v..
-
Ch14. AnimationsRay Wenderlich/SwiftUI 2021. 2. 14. 18:23
SwiftUI의 애니메이션은 UIKit보다 훨씬 간단하다. Animating state changes 직역해보면 물음표 짓게 만들지만 코드를 보면 이해가 된다. Adding animation Image(systemName: "chevron.up.square") .rotationEffect(.degrees(showDetails ? 0 : 180)) .animation(.default) 1, 2번 라인은 showDetails값에 따라 rotation을 업데이트한다. 즉 3번 라인이 없어도 무방하다. .animation(.default) 한 줄로 이미지가 회전하는 애니메이션이 생겼다. 0과 180을 오가는 애니메이션은 정방향 기준으로 시계방향으로 회전할 것이다. 하지만 180대신 -180을 넣으면 반시계방향으..
-
Ch13. Drawing & Custom GraphicsRay Wenderlich/SwiftUI 2021. 2. 14. 18:18
Creating shapes SwiftUI은 드로잉 Structure를 제공하는데 그 중 가장 간단한 것이 Rectangle이다. Rectangle() 이렇게 하면 검은색으로 화면이 뒤덮일것 .frame(width: 200, height: 200) 이렇게 추가해주면 화면 가운데에 200x200의 검은 사각형이 생긴다. .environment(\.colorScheme, .dark) 컬러 스킴에 따라 다른 색의 사각형이 생기는 것도 확인 가능 .fill(Color.blue) 명시적으로 컬러 선택도 가능 Using gradients .fill( LinearGradient(gradient: .init(colors: [Color.green, Color.blue]), startPoint: .bottomLeading..
-
Ch12. Conditional ViewsRay Wenderlich/SwiftUI 2021. 2. 14. 18:15
Displaying a modal sheet SwiftUI가 @State 프로퍼티를 사용하여 Modal을 띄우는 방식엔 2가지가 있음 Bool을 사용하여 true일 때 띄우기 Optional을 사용하여 not nil일 때 띄우기 @State private var isPresented = false Button(action: { self.isPresented.toggle() }) { HStack { someViews() } .sheet(isPresented: $isPresented, onDismiss: { print("Modal dismissed. State now: \(self.isPresented)") }) { viewToPresent() } } Programmatically dismissing a m..
-
Ch5. Combining OperatorsRay Wenderlich/Combine 2021. 2. 12. 01:51
Prepending prepend(Output...) let publisher = [3, 4].publisher publisher .prepend(1, 2) .sink(receiveValue: { print($0) }) .store(in: &subscriptions) 1 2 3 4 prepend(Sequence) Sequence프로토콜을 따르는 타입을 전달받을 수 있음 let publisher = [5, 6, 7].publisher publisher .prepend([3, 4]) .prepend(Set(1...2)) .prepend(stride(from: 6, to: 11, by: 2)) .sink(receiveValue: { print($0) }) .store(in: &subscriptions) 6 8..
-
Ch4. Filtering OperatorsRay Wenderlich/Combine 2021. 2. 12. 01:44
filter(_:) let numbers = (1...10).publisher numbers .filter { $0.isMultiple(of: 3) } .sink(receiveValue: { n in print("\(n) is a multiple of 3!") }) .store(in: &subscriptions) 3 is a multiple of 3! 6 is a multiple of 3! 9 is a multiple of 3! removeDuplicates() let words = "hey hey there! want to listen to mister mister ?" .components(separatedBy: " ") .publisher words .removeDuplicates() .sink(r..
-
SwiftUI에서 Modal을 Present하기카테고리 없음 2021. 2. 8. 01:47
import SwiftUI struct ContentView: View { @State private var isPresented = false var body: some View { Button("Present!") { self.isPresented.toggle() } .fullScreenCover(isPresented: $isPresented, content: FullScreenModalView.init) } } struct FullScreenModalView: View { @Environment(\.presentationMode) var presentationMode var body: some View { VStack { Text("This is a modal view") } .frame(maxWi..
-
Ch11. Lists & NavigationRay Wenderlich/SwiftUI 2021. 2. 7. 20:32
Ch11. Lists & Navigation Navigating through a SwiftUI app SwiftUI는 2가지 타입의 네비게이션을 제공한다. Flat - TabView를 사용 Hierarchical - NavigationView를 사용 Creating navigation views // 1 TabView { // 2 FlightBoard() // 3 .tabItem({ // 4 Image(systemName: "icloud.and.arrow.down") .resizable() Text("Arrivals") }) FlightBoard() .tabItem({ Image(systemName: "icloud.and.arrow.up") .resizable() Text("Departures") })..