Swift 3 - Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions

Viewed 4956

I got this error and I don't know how to solve it ! I'm searching all solutions but can't solve it!

Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions

Edit :

    func createTarget(id: Int) {

        listdata = dbHelpr.getDatabase(rowId: id)

        for data in listdata {

            let lengthOfChar : CGFloat = data.ans.length
            let yAxis : CGFloat = self.view.frame.height / 2 + 70

            var width: CGFloat = view.frame.size.width - 40 // frame width
            var targetWidth: CGFloat = (width - (lengthOfChar - 1) * 5) / lengthOfChar
            var totalWidth: CGFloat = (targetWidth * lengthOfChar) + ((lengthOfChar - 1) * 5)

            if targetWidth > 50 {
                targetWidth = 50
            }

            for tar in data.ans.characters {


                var xAxis : CGFloat = (width / 2) - (totalWidth / 2) + (tar * targetWidth) + (tar * 5) + 20

                let targetLabel = UILabel(frame: CGRect(x: xAxis, y: yAxis, width: targetWidth, height: 5.0))
                targetLabel.backgroundColor = .white
                targetLabel.layer.masksToBounds = true
                targetLabel.layer.cornerRadius = 5
                targetLabel.text = String(describing: tar)
                targetLabel.textAlignment = .center
                targetLabel.textColor = .white
                self.view.addSubview(targetLabel)

            }

        }

    }
3 Answers
Related