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
- iOS 버전 점유율
- conflicting access to memory
- Git Large File Storage
- rib
- Automatically manage signing
- Github file size
- RxCocoa
- iOS Target
- windowScene
- 로버트마틴형
- UICoordinateSpace
- App Signing
- ios
- 대머리깃허브
- RxSwift
- Large File Storage
- SWIFT
- swiftdocs
- 클린아키텍쳐
- Ribs
- 잡초가득블로그
- RIBs Tutorial
- coordinateSpace
- memory safety
- Concurrent
- Dispatch.main.sync
- Dependency Rule
- 메모리 접근 충돌
- Apple Certificate
- in-out
Archives
- Today
- Total
빙수왕의 개발일지
withIdentifier 하드코딩 말고 다른방법 본문
argument label이 withIdentifier인 메소드들..
예를들어 테이블뷰의 dequeueReusableCell이라던가 UIStoryboard의 instantiateViewController에서 하드코딩을 사용하게 된다.
withIdentifier: "cell"
withIdentifier: "DetailViewController"
이런식으루.. 근데 이럼 오타가 날수도 있고 유지보수에도 안좋아서 하드코딩은 피하는게 좋으니 다른 방법을 쓸 수 있다.
NSObject에 extension으로 identifier의 이름을 가져오는 프로퍼티를 만들어주면 다양한 객체에서 이 프로퍼티를 부르는 것 만으로 identifier의 이름을 하드코딩하지 않고 가져올 수 있다.
아래와 같이 NSObjectExtension.swift파일에 reuseIdentifier 프로퍼티를 정의하고
import Foundation
extension NSObject {
class var reuseIdentifier: String {
return String(describing: self)
}
}
아래처럼 불러서 사용할 수 있다.
tableView.dequeueReusableCell(withIdentifier: MyTableViewCell.reuseIdentifier, for: indexPath)
storyboard?.instantiateViewController(withIdentifier: DetailViewController.reuseIdentifier)
'개발 > iOS' 카테고리의 다른 글
Convenience init을 강제하는 법 (0) | 2020.11.29 |
---|---|
UICollectionView의 cellForItem이 nil이 나올 때 (0) | 2020.11.25 |
Swift 3개 이상의 값 비교하기 (0) | 2020.10.11 |
Playground 기능 (0) | 2020.08.07 |
_ sender: Any에서 언더바 _는 뭘까 - 전달인자 라벨, 와일드카드 식별자 (0) | 2020.07.18 |