Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace UICollectionViewDelegateFlowLayout by a reactive(RxSwift) call?

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?

like image 412
Marcone Avatar asked Mar 01 '17 21:03

Marcone


1 Answers

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.

like image 112
Daniel T. Avatar answered Oct 14 '22 02:10

Daniel T.