해당 메소드는 비용이 많이 들기 때문에 개발자가 직접 호출하는 것은 지양해야 함.
왼쪽이 layoutIfNeed, 오른쪽이 setNeedLayout 메소드를 적용한 결과이다.
layoutIfNeeded는 즉시 레이아웃을 반영하기 때문에 애니메이션이 보인다.
setNeedLayout은 다음 업데이트 주기를 기다리고 한번에 업데이트하기 때문에 즉시 업데이트되는 것 처럼 보인다.
복잡한 화면을 오토 레이아웃으로 모두 설정해주기 위해서는 많은 조건들이 필요하다. 하지만 stackview를 쓴다면 주어진 설정값에 맞게 stackview가 자동으로 조건을 조절해주기 때문에 개발자가 직접 설정해줘야하는 조건이 엄청 줄어든다.
stackview는 자체 컨텐츠가 없기 때문에 렌더링하는 수고가 들어가지 않는다. 따라서 일반 뷰보다 훨씬 빠르고 가볍다.
위 같이 복잡한 화면에서 레이아웃을 유지한 채로 뷰를 추가해야 된다. 오토 레이아웃의 경우에도 할 수는 있으나 굉장히 귀찮은 작업이 될 것이다.
모르겠다
리소스가 부족하면 자동으로 삭제
복사를 지원하지 않는 객체까지 포용
NSCopying 프로토콜을 채택하지 않은 객체까지 사용할 수 있다.
let mutableDic = NSMutableDictionary()
var dicKey: NSMutableString = "key" // K₁
mutableDic.setObject("one", forKey: dicKey) // K₂
dicKey.setString("changedKey") // still K₁
mutableDic.setObject("two", forKey: dicKey) // K₃
print(mutableDic.object(forKey: "key") ?? "") // "one"
print(mutableDic.object(forKey: "changedKey") ?? "") // "two"
let cache = NSCache<NSString, NSString>()
var cacheKey: NSMutableString = "key" // K₁
cache.setObject("one", forKey: cacheKey) // still K₁
cacheKey.setString("changedKey") // still K₁
cache.setObject("two", forKey: cacheKey) // still K₁!
print(cache.object(forKey: "key") ?? "") // ""
print(cache.object(forKey: "changedKey") ?? "") // "two"
세션의 타임아웃 값, 쿠키나 캐시 설정 등을 할 수 있음
URLSession.shared() // 기본 요청을 위한 세션, 사용자 정의 불가
URLSession(configuration: .default) // 기본적인 세션, 디스크 기반 캐싱
URLSession(configuration: .ephemral) // 디스크에 어떤 데이터도 저장하지 않고 메모리에 올림, 세션 만료시 관련된 데이터 삭제
URLSession(configuration: .background) // Suspended 상태에서도 업로드 다운로드 가능, 앱이 종료되고 다시시작하면 identifier를 사용해 진행 중이던 전송 상태를 찾을 수 있다.
세션 작업을 나타내는 추상 클래스
dequeueReuseableCell(:_)
이전에 객체를 반환한다.reconfigureRows(:_)
를 사용해서 기존의 셀 내용을 업데이트 하는 경우 메소드를 호출하지 않는다.alpha, 셀 선택 상태 등등
선택하지 않은 셀에도 체크 표시가 되어있는 것을 확인할 수 있다. 이는 셀을 재사용하기 때문에 preparedForReuse에서 초기화를 해 해결할 수 있다.
if UITraitCollection.userInterfaceStyle == .dark
/* 구현 */
Info.plist 에서 apperance를 Light로 하면 다크모드를 지원하지 않는다.
TableView는 수직으로만 스크롤이 가능하다.
NSLayoutConstraint.activate([NSLayoutConstraint(item: UIButton, attribute: .centerX, relatedBy: .equal, toItem: UIView, attribute: .centerX, multiplier: 1.0, constant: 0.0), ...])
let views = ["redView": redView,
"blueView": blueView,
"greenView": greenView]
let format1 = "V:|-[redView]-8-[greenView]-|"
let format2 = "H:|-[redView]-8-[blueView(==redView)]-|"
let format3 = "H:|-[greenView]-|"
var constraints = NSConstraint.constraints(withVisualFormat: format1,
options: alignAllLeft,
matrics: nil,
views: views)
constraints += NSConstraint.constraints(withVisualFormat: format2,
options: alignAllTop,
matrics: nil,
views: views)
constraints += NSConstraint.constraints(withVisualFormat: format3,
options: []
matrics: nil,
views: views)
NSConstraint.activateConstraints(constraints)
NSLayoutConstraint.activate([button.centerXAnchor.constraint(equalTo: view.centerXAnchor), ...])
우선 순위가 클수록 자신의 크기를 유지하려고 하고, 작을수록 크기가 늘어나는 속성
우선 순위가 클수록 자신의 크기를 유지하려 하고, 작을수록 크기가 작아지는 속성
참고자료
- https://zeddios.tistory.com/359
- https://velog.io/@zeke/difference-between-setNeedsLayoutsetNeedsDisplay
- https://h4njun.tistory.com/entry/setNeedsDisplay-setNeedsLayout
- https://velog.io/@eddy_song/stack-view
- https://firekokoma.tistory.com/344
- https://inuplace.tistory.com/1050
- https://jeong9216.tistory.com/464
- https://sihyungyou.github.io/iOS-dequeueReusableCell/
- https://bmwe3.tistory.com/1773
- https://one10004.tistory.com/121
- https://github.com/lunchScreen/Interview_Questions/issues/25
- https://github.com/iOS-SOPT-iNNovation/iOS_Traning/issues/20
- https://github.com/lunchScreen/Interview_Questions/issues/36