title: How to make UICollectionViewFlowLayout itemSize dynamic for screen size
body: <p>I am working programmatically (no storyboard) and am having trouble making layout.itemSize dynamic for different screen sizes. I get this error message: </p>
  
  <blockquote>
    <p>"UICollectionView must be initialised with a non-nil layout parameter" </p>
  </blockquote>
  
  <p>with the following code in my implementation file: </p>
  
  <pre><code>- (instancetype)init 
  {
      UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  
      CGSize size = self.collectionView.bounds.size;
  
      layout.itemSize = CGSizeMake(size.width, size.height);
  
      [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
  
      layout.minimumLineSpacing = 100.0;
  
      layout.headerReferenceSize = CGSizeMake(0.0, 50.0);
  
      return (self = [super initWithCollectionViewLayout:layout]);
  }
  </code></pre>
  
  <p>I don't get the error message if I use "100,100" for example for <code>layout.itemSize</code>. Is there a way to make it dynamic though?</p>
  
  <p>I am new to Objective-C so would appreciate any help on what I am doing incorrectly.</p>