Why are you adding in your View Controller:
var newCollection = UICollectionView()
Since you already added it in your view?, instead you should set your view as your view type, and reference that collection view from the your View Controller.
var myView: CustomView
myView = MyView()
view = myView
let collectionView = myView.collectionView
Every collection view needs a UICollectionViewLayout subclass in its initializer, now UICollectionViewLayout is a abstract class, you can make your own, but you could also use UICollectionViewFlowLayout()
in this case:
var newCollection = UICollectionView(collectionViewLayout: UICollectionViewFlowLayout())
Now you did add it on your first view, but not in the second one, again check why the second one exists, that's the one causing the problems.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…