代码会使编译器变慢,如何解决?

时间:2018-09-07 23:06:36

标签: ios swift xcode uicollectionview

所以我用this website来找出导致我的编译器编译了将近2分钟的原因

100801.11ms /ViewControllers/FastGame/FastGameVC.swift:160:10   instance method configureCollectionView()\

这是我的代码:

func configureCollectionView()
{
    let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    let screenSize: CGRect = UIScreen.main.bounds
    if (screenSize.size.width > 320)
    {
        if (self.currentLogo!.originalRandomLetters!.count > 14)
        {
            layout.sectionInset = UIEdgeInsets(top: 20, left: 8, bottom: 20, right: 8)
            self.constaintHeightViewRandomLetter.constant = 26 + (self.collectionLetters.frame.width/8 - 3) * 2 + 20
        }
        else
        {
            layout.sectionInset = UIEdgeInsets(top: 20, left: 8 + (self.view.frame.width/8 - 3) / 2, bottom: 20, right: 8 + (self.view.frame.width/8 - 3) / 2)
            self.constaintHeightViewRandomLetter.constant = 26 + (self.collectionLetters.frame.width/8 - 3) * 2 + 20
        }
    }
    else
    {
        if (self.currentLogo!.originalRandomLetters!.count > 14)
        {
            layout.sectionInset = UIEdgeInsets(top: 10, left: 8, bottom: 10, right: 8)
            self.constaintHeightViewRandomLetter.constant = 10 + (self.collectionLetters.frame.width/8 - 3) * 2
        }
        else
        {
            layout.sectionInset = UIEdgeInsets(top: 10, left: 8 + (self.view.frame.width/8 - 3) / 2, bottom: 10, right: 8 + (self.view.frame.width/8 - 3) / 2)
            self.constaintHeightViewRandomLetter.constant = 10 + (self.collectionLetters.frame.width/8 - 3) * 2
        }
    }

    layout.itemSize = CGSize(width: self.view.frame.width/8 - 3, height: self.view.frame.width/8 - 3)
    layout.minimumInteritemSpacing = 1
    layout.minimumLineSpacing = 4
    self.collectionLetters!.collectionViewLayout = layout
    //self.constaintHeightViewRandomLetter.constant = 26 + (self.collectionLetters.frame.width/8 - 3) * 2 + 20
    self.viewContainerRandomLetters.layoutIfNeeded()
    self.viewAnswerLetters.layoutIfNeeded()
}

我如何优化此代码部分以使其正常工作,并且不减慢编译器的速度?

感谢进阶!

0 个答案:

没有答案
相关问题