Skip to content

Instantly share code, notes, and snippets.

@lfaoro
Created September 10, 2014 07:47
Show Gist options
  • Save lfaoro/c7fea170d6da0f1878fe to your computer and use it in GitHub Desktop.
Save lfaoro/c7fea170d6da0f1878fe to your computer and use it in GitHub Desktop.
I have all these cases that assign a lengthy subview repetitive code:
case (1, 1), (1, 8):
var value = Piece(color: .w, shape: .R)
var pieceImg = NSImage(named: "wR")
var pieceView = NSImageView(frame: CGRect(x: squareX, y: squareY, width: cellLength, height: cellLength))
pieceView.image = pieceImg
boardView.addSubview(pieceView, positioned: .Above, relativeTo: nil)
What if I assign just the:
var value = Piece(color: .w, shape: .P)
cellState[notation] = value
to every case: and then do an iteration for the subview assignment?
for n in notation
if cell != nil {
var pieceImg = "piece"
addView.image = pieceImg
boardView.addSubview addView
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment