본문 바로가기

iOS/STUDY

(56)
[iOS] 레이아웃이 깨졌을 때 콘솔창 버그 ㅋ2022-04-26 13:03:40.451472+0900 DoGit[4494:107137] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "", "", "", "" ) Will attemp..
[iOS] cellRegistration: cell 배경색 바꾸기 컬렉션 리스트뷰를 사용하다가 cell의 배경색을 바꾸려고 했지만 backgroundColor를 바꾸는 것으로는 바뀌지 않았다. cell.backgroundColor = .backgroundColor 해결방법 backgroundView를 배경색 view로 넣어주었더니 변경되었다. let background: UIView = { let view = UIView() view.backgroundColor = .backgroundColor return view }() cell.backgroundView = background 비슷한 방법으로 cell이 클릭된 것처럼 보이지 않게 하려면 selectedBackgroundView를 바꿔준다. let selectedBackground: UIView = { let vie..
[iOS] reloadItems, reconfigureItems 차이점 우선 이 함수를 쓰게 된 이유를 말해보자면 개인 프로젝트에서 Diffable datasource를 사용하면서 snapshot도 함께 사용하게 되었습니다. 만들던 프로젝트는 Todo 앱으로 버튼 클릭 시 isDone 변수의 값에 따라 UI가 업데이트되어야 했는데, 바뀐 Todo에 대하여 snapshot을 업데이트해도 UI가 업데이트되지 않았습니다. 해서 cell registration을 이용해 datasource를 다시 만들어 apply 시켰더니 적용은 됐지만 애니메이션 적용은 얻을 수 없었습니다. -> 사실 reloadItems, reconfigureItems 을 사용했어야 했는데 이제야 발견했고.. 발견한 김에 두가지 함수에 대해 차이점을 정리해보려고 합니다. 우선 경험으로 얻은 차이점을 보고 자세하게..
[iOS] CAGradientLayer (그라데이션 배경) https://developer.apple.com/tutorials/app-dev-training/creating-a-gradient-background Apple Developer Documentation developer.apple.com iOS App Dev Tutorials 끝이 보이네요! 이번엔 그라데이션 배경을 만드는 방법에 대해 알아보겠습니다. segment (Today, Future, All) 마다 그라데이션 색상을 다르게 적용해볼 것입니다. 우선 사용할 CAGradientLayer 에 대해 알아보겠습니다. CAGradientLayer A layer that draws a color gradient over its background color, filling the shape of the..
[iOS] @discardableResult @ : Attribute 키워드 컴파일러에게 추가적인 정보를 알려주는 역할을 합니다. 1. 선언에 추가적인 정보를 제공하거나 2. 타입에 추가적인 정보를 제공합니다. // 1. 선언 @available(iOS 10.0) class MyClass { ... } // 2. 타입 func doSomething(completion: @escaping()->()) { ... } @discardableResult 함수의 리턴값을 활용하지 않는 경우에 사용합니다. 일반적으로 return값을 반환하는 함수를 선언하고 호출할 때, 이 값을 사용하지 않는다면 경고창으로 결과값을 사용하지 않는다고 알려줍니다. 이 때 @discardableResult 를 함수위에 써주면 "결과값을 사용하지 않아도 된다" 라고 컴파일러에게 정..
[iOS] UICollectionReusableView (diffable datasource) https://developer.apple.com/tutorials/app-dev-training/creating-a-progress-view Apple Developer Documentation developer.apple.com 오늘도 apple의 튜토리얼을 보고 정리한 내용입니다. 잘못된 내용이 있을 수도 있음을... 우선 UICollectionReusableView를 사용하는 이유가 무엇인지? - 아래처럼 Header를 만들어주기 위해서 - 스크롤될 때 삭제하지 않고 재사용 큐에 배치하기 위해서 어떻게 UICollectionReusableView를 사용해서 커스텀 헤더를 만들 수 있는지 한번 알아보겠습니다. UICollectionReusableView A view that defines the b..
[Swift] Copy-on-Write 최적화 코드 상에서 값을 복사해서 담는다 하더라도, 실제 값이 바뀌기 전까지는 하나의 메모리 값을 공유해서 사용한다. 메모리를 적게 차지하기 위해서 Swift 언어가 내부에서 처리하는 매커니즘 코드로 한번 살펴보겠습니다. var array = [1, 2, 3, 4, 5, 6] var subArray = array[0...2] subArray.append(7) subArray 배열을 생성할 때 array의 배열 [0...2] 부분을 대입했지만 이때 값의 복사가 아니라 동일한 메모리 공간을 가르키고 있게 됩니다. 그리고 값의 변경이 일어날 때 (여기서 append()) 값이 복사됩니다. Swift에서는 원시타입 구조체(Int, Double, String)와 Array, Set, Dictionary 등 컬렉션 구조체..
[iOS] UISegmentedControl https://developer.apple.com/tutorials/app-dev-training/filtering-reminders iOS App Dev Tutorials 를 공부하고 작성한 글입니다. UISegmentedControl A horizontal control that consists of multiple segments, each segment functioning as a discrete button. 여러 segment로 구성된 수평 컨트롤로, 각 segment는 개별 버튼으로 작동합니다. - 각 컨트롤은 제목 또는 이미지(UIImage)로 표시할 수 있다고 합니다. - UISegmentedControl 객체는 특정 width가 설정되어 있지 않은 한 super view 내에 비례적으..