[iOS/Swift] legacy_constructor lint error 해결

김혜수·2023년 5월 13일
0

iOS를 개발하면서..

목록 보기
18/20

왜 빌드할땐 안뜬건지 모르겠지만..

public func setLineSpacing(lineSpacing: CGFloat) {
	if let text = self.text {
	let attributedStr = NSMutableAttributedString(string: text)
	let style = NSMutableParagraphStyle()
	style.lineSpacing = lineSpacing
    attributedStr.addAttribute(NSAttributedString.Key.paragraphStyle, value: style, range: NSMakeRange(0, attributedStr.length))
	self.attributedText = attributedStr
}

여기서 NSMakeRange가 옛날함수여서 그렇다.
얘를 다음과 같이 NSRange로 바꿔주면 된다.

 public func setLineSpacing(lineSpacing: CGFloat) {
        if let text = self.text {
            let attributedStr = NSMutableAttributedString(string: text)
            let style = NSMutableParagraphStyle()
            style.lineSpacing = lineSpacing
            attributedStr.addAttribute(
                NSAttributedString.Key.paragraphStyle,
                value: style,
                range: NSRange(location: 0, length: attributedStr.length))
            self.attributedText = attributedStr
        }
    }
profile
iOS를 좋아하는 사람

0개의 댓글