Problem
I am building a collage of photos from an array of images that I am placing onto a tableview. I want to make the images wrap when the number
Since you're using Swift 2.0: UIStackView does exactly what you're trying to do manually, and is significantly easier to use than UICollectionView. Assuming you're using Storyboards, creating a prototype TableViewCell with multiple nested UIStackViews should do exactly what you want. You'll just need to make sure that the UIImages you're inserting are all the same aspect ratio if that's what you want.
Your algorithm is highly inefficient because it has to re-draw, with multiple Core Animation transforms, every image any time you add or remove an image from your array. UIStackView supports dynamically adding and removing objects.
If you still, for some reason, need to snapshot the resulting collage as a UIImage, you can still do this on the UIStackView.