mac-cain13 / R.swift

Strong typed, autocompleted resources like images, fonts and segues in Swift projects
MIT License
9.5k stars 764 forks source link

Not correctly generating code for CollectionViewCell in Storyboard #377

Open alexandre-g opened 6 years ago

alexandre-g commented 6 years ago

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.

tomlokhorst commented 6 years ago

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.

alexandre-g commented 6 years ago

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: `

...`
tomlokhorst commented 6 years ago

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