I'm making an app that draws elementary cellular automata. Currently I'm using UIBezierPath to draw the cells in a custom UIView:
var path : UIBezierPath
for (heightIndex, row) in stateMatrix!.enumerate() {
for (widthIndex, cell) in row!.enumerate() {
let myRect = CGRect(x: cellWidth * CGFloat(widthIndex), y: cellWidth * CGFloat(heightIndex), width: cellWidth, height: cellWidth)
path = UIBezierPath(rect: myRect)
if cell == "x" {
Constants.OnColor.setFill()
Constants.OnColor.setStroke()
} else {
Constants.OffColor.setFill()
Constants.OffColor.setStroke()
}
path.fill()
path.stroke()
}
}
The grid I'm drawing is approximately n * 6n cells. This code works fine when n is small, but it obviously doesn't scale well (on my iPhone 4s, with n = 150, it takes about a minute and a half). Clearly there must be a better way to do this than calling UIBezierPath a few hundred thousand times. What would be a better way to approach this?