Is there a solution for this problem ?
class ViewController : UIViewController {
let collectionFlowLayout = UICollectionViewFlowLayout()
let collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: collectionFlowLayout)
}
xcode gives me the following error
ViewController.swift: 'ViewController.Type' does not have a member named 'collectionFlowLayout'
i could make it an optional and initialise it in the init method, but i'm looking for a way to make the collectionview a let and not a var
You can assign initial values to constant member variables in your initializer. There's no need to make it a var
or optional.
class ViewController : UIViewController {
let collectionFlowLayout = UICollectionViewFlowLayout()
let collectionView : UICollectionView
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?)
{
self.collectionView = UICollectionView(frame: CGRectZero,
collectionViewLayout: self.collectionFlowLayout);
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil);
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With