• 카테고리

    질문 & 답변
  • 세부 분야

    모바일 앱 개발

  • 해결 여부

    미해결

그래프 강좌 실행시 Thread오류 납니다.

19.04.20 14:56 작성 조회수 119

0

class ViewController: UIViewController {

@IBOutlet weak var graph1Height: NSLayoutConstraint!

@IBOutlet weak var graph2Height: NSLayoutConstraint!

@IBOutlet weak var graph3Height: NSLayoutConstraint!

@IBOutlet weak var graph4Height: NSLayoutConstraint!

@IBOutlet weak var graph5Height: NSLayoutConstraint!

override func viewDidLoad() {

super.viewDidLoad()

graph1Height = graph1Height.changeMultiplier(value: 0.9 as! CGFont) <- Thread 오류

graph2Height = graph2Height.changeMultiplier(value: 0.8 as! CGFont)

graph3Height = graph3Height.changeMultiplier(value: 0.7 as! CGFont)

graph4Height = graph4Height.changeMultiplier(value: 0.8 as! CGFont)

graph5Height = graph5Height.changeMultiplier(value: 0.5 as! CGFont)

}

}

extension NSLayoutConstraint {

func changeMultiplier(value: CGFont) -> NSLayoutConstraint {

    NSLayoutConstraint.deactivate([self])

let newConstraint = NSLayoutConstraint.init(item: self.firstItem!, attribute: self.firstAttribute, relatedBy: self.relation, toItem: self.secondItem, attribute: self.secondAttribute, multiplier: value as! CGFloat, constant: self.constant)

newConstraint.priority = self.priority

newConstraint.shouldBeArchived = self.shouldBeArchived

newConstraint.identifier = self.identifier

NSLayoutConstraint.activate([newConstraint])

return newConstraint

}

}

답변 3

·

답변을 작성해보세요.

0

댓글다신 코드에 타입이 잘못되어 있네요

CGFont로 되어 있는 부분을 모두 CGFloat으로 변경하시면 해결될 겁니다.

0

vampireahn님의 프로필

vampireahn

질문자

2019.04.23

역시 스레드 에러 납니다 ㅠㅠ

0

안녕하세요

changeMultiplier 안에

DispatchQueue.main.async {

...

...

}

이렇게 main queue로 감싸고 실행해 보시면 스레드 문제는 해결될 겁니다.