7

Is there a way to replace the method

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize

from the UICollectionViewDelegateFlowLayout protocol by something reactive using RxSwift?

Marcone
  • 855
  • 2
  • 8
  • 17

1 Answers1

3

Protocol methods that return values are pull based and as such are incompatible with Rx's push based philosophy. Not only is it currently impossible to replace that particular method with an Observable, it will never be possible.

The best you can do is implement the method by returning the value in a Variable and use Rx to push data into the Variable. When the collection view needs the size for the item in question, it will ask for it by calling this method.

Daniel T.
  • 32,821
  • 6
  • 50
  • 72