2020/02/23 4

[iOS]contentInset, contentOffset

contentInset 하위뷰 콘텐츠의 상하좌우로 안쪽 여백을 주는 것입니다. (바깥쪽 x) https://developer.apple.com/documentation/uikit/uiscrollview/1619406-contentinset contentInset - UIScrollView | Apple Developer Documentation Instance Property contentInset The custom distance that the content view is inset from the safe area or scroll view edges. DeclarationDiscussionUse this property to extend the space between your content a..

iOS 2020.02.23

[iOS] CALayer란

CALayer란 UIView에서 렌더링, 레이아웃, 애니메이션 등을 관리하는 Core Animation클래스인 CALayer가 있습니다. 모든 UIVIew는 layer 프로퍼티를 가지고 있습니다. UIView는 레이아웃과 터치 이벤트 처리 등 많은 작업을 하게되는데 실제로 뷰 위에 컨텐츠나 애니메이션을 그리는 행위는 직접적으로 다루지 않고 UIKit이 Core Animation에 위임하게 되고, shadow, corner radius, border, 3D transform, masking contents, animation과 같은 작업들을 CALayer가 담당하게 됩니다. 사용 CALayer를 사용하기 위해서는 QuartzCore.framework가 추가되어있어야 합니다. 특징 - CALayer에서 CA..

iOS 2020.02.23

[Swift] rethrows란

함수나 메서드는 rethrows키워드를 사용하여 자신의 매개변수로 전달받은 함수가 오류를 던진다는 것을 나타낼 수 있습니다. 최소 하나 이상의 오류 발생 가능한 함수를 매개변수로 전달받아야합니다. 간단한 예제를 보면서 살펴보겠습니다. enum MyError: Error { case cannotDivide } func divideNumber(first: Float, second: Float) throws -> Float { if second == 0 { throw MyError.cannotDivide } return first/second } func calculateFunction(function: (Float, Float) -> Float) { print(function(2, 3)) } calculat..

Swift 2020.02.23

[Swift] 에러처리 전략

안녕하세요. iOS앱을 개발하면서 Swift로 에러처리에 대한 글을 작성해보려고 합니다. 에러처리를 적절하게 선택하면 코드 품질이 향상되고 프로그래머 의도가 명확해집니다. 그래서 언제 무엇을 사용해야하는지를 간단하게 적어보겠습니다. 에러는 크게 두 가지 범주로 나눌 수 있습니다. 프로그래머가 제어할 수 없는 런타임에 대한 에러(Optional, throw) - recoverable 프로그래머의 실수에 대한 에러 (Assertion, FatalError) - non-recoverable 1)Optional 옵셔널은 값이 있을 경우, 없으 경우에 대한 결과를 나타냅니다. try? 표현식을 사용합니다. 언제? - 에러가 간단할 때 예제 func someThrowingFunction() throws -> Int..

Swift 2020.02.23