R.swift icon indicating copy to clipboard operation
R.swift copied to clipboard

Not correctly generating code for CollectionViewCell in Storyboard

Open alexandre-g opened this issue 6 years ago • 3 comments

Hi, trying to replace: let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "logosAddCell", for: indexPath)

with let cell = collectionView.dequeueReusableCell(withReuseIdentifier: R.reuseIdentifier.logosAddCell, for: indexPath)!

But getting: Cannot convert value of type 'ReuseIdentifier<UIView>' to expected argument type 'String'

Working for table view but not for collection views. Swift 4

Any ideas?

Edit: It seems to work when the cell has a custom class set.

alexandre-g avatar Dec 18 '17 00:12 alexandre-g

I don't entirely understand your setup.

What is the type of your R.reuseIdentifier.logosAddCell? Custom classes for CollectionView cells should be subclasses of UICollectionViewCell.

I would expect logosAddCell to be of type Rswift.ReuseIdentifier<UIKit.UICollectionViewCell> or something more specific. That should work with the custom dequeueReusableCell overload from the Rswift library.

tomlokhorst avatar Dec 18 '17 22:12 tomlokhorst

So when I have the cell selected, it's of type UICollectionViewCell as expected (but maybe if you don't specify a custom subclass, Xcode treats it as UIView?) image

The generated code is: static let logosAddCell: Rswift.ReuseIdentifier<UIKit.UIView> = Rswift.ReuseIdentifier(identifier: "logosAddCell")

Actually, just looked in the storyboard and it's a collectionViewCell: <cells> <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="logosAddCell" id="UkE-BZ-9X8">...

alexandre-g avatar Dec 19 '17 00:12 alexandre-g

I see, you're using a storyboard, I was testing this with a nib file.

It seems there's a bug in R.swift where it doesn't correctly generate the code for collection view cells in storyboards. It does work correctly for nibs.

Note to self: this table in Storyboard.swift should include all elements that can occur in a storyboard, but at least the once from Nib.swift

tomlokhorst avatar Dec 19 '17 00:12 tomlokhorst