내 응용 프로그램 내부에 일부보기를 표시하기 위해 디버깅 목적으로 사용하는보기 컨트롤러가 있습니다 (로컬 xcode 빌드에만 해당, 응용 프로그램 저장소 버전에는이 컨트롤러가 없음).UILabel.attributedText를 동일한 값으로 설정하는 데 비용이 많이 듭니까?
이 컨트롤러에는 내부 구성 요소의 상태를 반영하고자하는 레이블이 있습니다 (특히 해당 구성 요소의 활성화 또는 비활성화 여부를 표시해야 함).
내 질문 :
# 1 : 그것은 예전으로 비싼 같은 값으로 UILabel의의 .attributedText
속성을 설정하는 것입니다, 아니면 이전 값을 캐시해야하고 변경하는 경우에만 속성을 설정 ?
# 2 : .text
(속성이 아닌) 속성은 무엇입니까?
나는 현재 다음과 같은 코드를 사용하고 있습니다 : 나는 몇 가지 숫자를 공유하기 전에
// Schedule timer to update the control panel. (This is debug-only, so not worth
// the complexity of making this event-based)
Timer.scheduledTimer(withTimeInterval: 0.5,
repeats: true) { [weak self] timer in
DispatchQueue.main.async {
// Stop timer if we've been dealloced or are no longer being presented
guard let strongSelf = self,
strongSelf.isBeingPresented else
{
timer.invalidate()
return
}
// "Something Enabled/Disabled" label
let somethingIsEnabled = strongSelf.someDepenency.isEnabled
let somethingEnabledString = NSMutableAttributedString(string: "Something ")
somethingEnabledString.append(NSAttributedString(string: isEnabled ? "Enabled" : "Disabled",
attributes: isEnabled ? nil : [NSForegroundColorAttributeName: UIColor(xtHardcodedHexValue: "0xCD0408")]))
strongSelf.somethingEnabledLabel?.attributedText = somethingEnabledString
}
}
실제로 성능 문제가 있습니까? 이 질문에 대한 진정한 요점은없는 것 같습니다. – rmaddy
글쎄, 내 팀원 중 일부는 (CR 동안) 걱정하고있다. 당신 말이 맞아요, 그것은 대부분 호기심이고 UIKit에 대한 이해를 높이기 위해서입니다. 라벨이 초당 60x를 업데이트해야한다면 어떨까요? 'attributedText'라는 레이블을 100 개나 가지고 있다면 어떨까요? – Julien
테스트합니다. 성과를 측정합니다. 실제로 문제가있는 경우에만 그것에 대해 아무 것도 시도하지 않습니다. – rmaddy