2017-01-13 3 views
0

私は単純なアプリケーションを構築しており、コードですべてのUIを作成しています。このプロジェクトは、いくつかのラベルの制約を追加し、ストーリーボードにいくつかのものを追加するまでうまくいきました(私はワイヤフレームに役立つストーリーボードを見つけました)。ビューラベルに制約を加えた後にXcodeがフリーズする

ビルドしようとすると、Swiftファイルのコンパイル中にビルドがフリーズします(Xcodeはまだ入力に応答します)。

、私のクラスはこのように見えた(プロジェクトが建設するとき)前に:今(それが構築しないとき)

class CurrentWeatherView: UIView { 

    weak var tempLowLabel: UILabel! = UILabel() 
    weak var tempLowIcon: UILabel! = UILabel() 
    weak var tempHighLabel: UILabel! = UILabel() 
    weak var tempHighIcon: UILabel! = UILabel() 

    weak var precipChanceLabel: UILabel! = UILabel() 
    weak var precipIconLabel: UILabel! = UILabel() 
    weak var humidity: UILabel! = UILabel() 
    weak var humidityIconLabel: UILabel! = UILabel() 

    weak var icon: UILabel! = UILabel() 
    weak var tempLabel: UILabel! = UILabel() 

    weak var summaryLabel: UILabel! = UILabel() 
    weak var summaryScroll: UIScrollView! = UIScrollView() 
} 

、それは次のようになります。

class CurrentWeatherView: UIView { 

    weak var tempLowLabel: UILabel! = UILabel() 
    weak var tempLowIcon: UILabel! = UILabel() 
    weak var tempHighLabel: UILabel! = UILabel() 
    weak var tempHighIcon: UILabel! = UILabel() 

    weak var precipChanceLabel: UILabel! = UILabel() 
    weak var precipIconLabel: UILabel! = UILabel() 
    weak var humidityLabel: UILabel! = UILabel() 
    weak var humidityIconLabel: UILabel! = UILabel() 

    weak var icon: UILabel! = UILabel() 
    weak var iconSummaryLabel: UILabel! = UILabel() 
    weak var tempLabel: UILabel! = UILabel() 

    weak var summaryLabel: UILabel! = UILabel() 
    weak var summaryScroll: UIScrollView! = UIScrollView() 

    func setUpLayout() { 

     self.addSubview(tempLowLabel) 
     self.addSubview(tempLowIcon) 
     self.addSubview(tempHighLabel) 
     self.addSubview(tempHighIcon) 
     self.addSubview(precipChanceLabel) 
     self.addSubview(precipIconLabel) 
     self.addSubview(humidityLabel) 
     self.addSubview(humidityIconLabel) 
     self.addSubview(icon) 
     self.addSubview(iconSummaryLabel) 
     self.addSubview(tempLabel) 
     self.addSubview(summaryLabel) 
     self.addSubview(summaryScroll) 

     tempLowLabel.translatesAutoResizingMaskToConstraints = false 
     tempLowIcon.translatesAutoResizingMaskToConstraints = false 
     tempHighLabel.translatesAutoResizingMaskToConstraints = false 
     tempHighIcon.translatesAutoResizingMaskToConstraints = false 
     precipChanceLabel.translatesAutoResizingMaskToConstraints = false 
     precipIconLabel.translatesAutoResizingMaskToConstraints = false 
     humidityLabel.translatesAutoResizingMaskToConstraints = false 
     humidityIconLabel.translatesAutoResizingMaskToConstraints = false 
     icon.translatesAutoResizingMaskToConstraints = false 
     iconSummaryLabel.translatesAutoResizingMaskToConstraints = false 
     tempLabel.translatesAutoResizingMaskToConstraints = false 
     summaryLabel.translatesAutoResizingMaskToConstraints = false 
     summaryScroll.translatesAutoResizingMaskToConstraints = false 

     NSLayoutConstraint.activate([ 
       NSLayoutConstraint(item: tempHighIcon, attribute: .left, relatedBy: .equal, toItem: self, attribute: .left, multiplier: 1.0, constant: 12), 
       NSLayoutConstraint(item: tempHighIcon, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: 22), 
       tempHighIcon.heightAnchor.constraint(equalToConstant: 22), 
       tempHighIcon.widthAnchor.constraint(equalToConstant: 16), 

       NSLayoutConstraint(item: tempLowIcon, attribute: .left, relatedBy: .equal, toItem: self, attribute: .left, multiplier: 1.0, constant: 12), 
       NSLayoutConstraint(item: tempLowIcon, attribute: .top, relatedBy: .equal, toItem: tempHighIcon, attribute: .bottom, multiplier: 1.0, constant: 5), 
       tempLowIcon.heightAnchor.constraint(equalToConstant: 22), 
       tempLowIcon.widthAnchor.constraint(equalToConstant: 16), 

       NSLayoutConstraint(item: tempHighLabel, attribute: .left, relatedBy: .equal, toItem: tempHighIcon, attribute: .right, multiplier: 1.0, constant: 8), 
       NSLayoutConstraint(item: tempHighLabel, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: 22), 
       tempHighIcon.heightAnchor.constraint(equalToConstant: 22), 
       tempHighIcon.widthAnchor.constraint(equalToConstant: 42), 

       NSLayoutConstraint(item: tempLowLabel, attribute: .left, relatedBy: .equal, toItem: tempLowIcon, attribute: .right, multiplier: 1.0, constant: 8), 
       NSLayoutConstraint(item: tempLowLabel, attribute: .top, relatedBy: .equal, toItem: tempHighLabel, attribute: .bottom, multiplier: 1.0, constant: 5), 
       tempHighIcon.heightAnchor.constraint(equalToConstant: 22), 
       tempHighIcon.widthAnchor.constraint(equalToConstant: 42), 

       NSLayoutConstraint(item: icon, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: 22), 
       icon.centerXAnchor.constraint(equalTo: self.centerXAnchor), 
       icon.widthAnchor.constraint(equalToConstant: 85), 
       icon.heightAnchor.constraint(equalToConstant: 85), 

       iconSummaryLabel.centerXAnchor.constraint(equalTo: icon.centerXAnchor), 
       iconSummaryLabel.centerYAnchor.constraint(equalTo: icon.centerYAnchor), 
       iconSummaryLabel.heightAnchor.constraint(equalToConstant: 75), 
       iconSummaryLabel.widthAnchor.constraint(equalToConstant: 75), 

       NSLayoutConstraint(item: tempLabel, attribute: .top, relatedBy: .equal, toItem: icon, attribute: .bottom, multiplier: 1.0, constant: 8), 
       tempLabel.centerXAnchor.constraint(equalTo: self.centerXAnchor), 
       tempLabel.widthAnchor.constraint(equalToConstant: 85), 
       tempLabel.heightAnchor.constraint(equalToConstant: 25), 

       NSLayoutConstraint(item: summaryScroll, attribute: .left, relatedBy: .equal, toItem: self, attribute: .left, multiplier: 1.0, constant: 12), 
       NSLayoutConstraint(item: summaryScroll, attribute: .right, relatedBy: .equal, toItem: self, attribute: .right, multiplier: 1.0, constant: 12), 
       NSLayoutConstraint(item: summaryScroll, attribute: .bottom, relatedBy: .equal, toItem: self, attribute: .bottom, multiplier: 1.0, constant: 8), 
       summaryScroll.heightAnchor.constraint(equalToConstant: 21), 
       summaryScroll.centerXAnchor.constraint(equalTo: self.centerXAnchor), 

       NSLayoutConstraint(item: precipChanceLabel, attribute: .right, relatedBy: .equal, toItem: self, attribute: .right, multiplier: 1.0, constant: 12), 
       NSLayoutConstraint(item: precipChanceLabel, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: 22), 
       precipChanceLabel.heightAnchor.constraint(equalToConstant: 22), 
       precipChanceLabel.widthAnchor.constraint(equalToConstant: 42), 

       NSLayoutConstraint(item: humidityLabel, attribute: .right, relatedBy: .equal, toItem: self, attribute: .right, multiplier: 1.0, constant: 12), 
       NSLayoutConstraint(item: humidityLabel, attribute: .top, relatedBy: .equal, toItem: precipChanceLabel, attribute: .bottom, multiplier: 1.0, constant: 5), 
       humidityLabel.heightAnchor.constraint(equalToConstant: 22), 
       humidityLabel.widthAnchor.constraint(equalToConstant: 42), 

       NSLayoutConstraint(item: precipIconLabel, attribute: .right, relatedBy: .equal, toItem: precipChanceLabel, attribute: .left, multiplier: 1.0, constant: 8), 
       NSLayoutConstraint(item: precipIconLabel, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: 22), 
       precipIconLabel.heightAnchor.constraint(equalToConstant: 22), 
       precipIconLabel.widthAnchor.constraint(equalToConstant: 16), 

       NSLayoutConstraint(item: humidityIconLabel, attribute: .right, relatedBy: .equal, toItem: humidityLabel, attribute: .left, multiplier: 1.0, constant: 8), 
       NSLayoutConstraint(item: humidityIconLabel, attribute: .top, relatedBy: .equal, toItem: precipIconLabel, attribute: .bottom, multiplier: 1.0, constant: 5), 
       humidityIconLabel.heightAnchor.constraint(equalToConstant: 22), 
       humidityIconLabel.widthAnchor.constraint(equalToConstant: 16), 
      ]) 
    } 
} 

が全てですこれらの制約は、Xcodeにとって非常に大きなものですか?

また、インデックス作成が完了しません。

私はプロジェクトのクリーニング、ビルドフォルダのクリーニング、派生データの削除、マシンの再起動、Xcodeの再起動、Xcodeの更新、コード最適化レベルのチェックを試みましたが、どれも役に立たなかった。

+1

(1)私は「インデックス作成....」と表示されたときにXcodeだけを許可することを学びました。あなたの好きな飲​​み物のカップをつかんで、オンラインで跳ね返り、昼寝してください。それを中断しないでください。 :-)(2)あなたのUIKitの値を弱く設定している理由は不思議です。これはIBOutletのデフォルトですが、私は決してその方法を宣言しません。それは自分のやり方が正しいことを意味するものではなく、大きな違いです。 – dfd

+0

@dfd私が弱点を選んだ理由は、1)IBOutletsがそのように宣言されたので、あなたがそれをやるべきだと思ったのです。 2)私はそれが記憶を助けると思った。特定の理由はありますか?また、インデックス作成とは何ですか、なぜそれを混乱させないのですか? –

+0

ここでの制約の数は何も注目に値しません。 Xcodeはこれを(そしてはるかに)処理することができます。 – d00dle

答えて

0

Xcodeバージョン8.3ベータ版に更新することでこの問題を解決できました。 Xcode 8.3もリリースされました。

関連する問題