GithubHelp home page GithubHelp logo

Comments (2)

AliSoftware avatar AliSoftware commented on July 20, 2024

Hi

This is indeed a very strange warning. Like you, I can't see how UICollectionViewCell could already conform to Reusable from inside UIKit… the warning is probably misleading and coming from another problem with the wrong diagnostics from the compiler, maybe?

Strangely enough, I opened a random project on my Mac which uses Reusable, and added extension UICollectionViewCell: Reusable {} somewhere in the code and rebuild the project, and:

  • I do have a new error after adding this new line, but which is justified, and is on an existing code I had in the project which looks like class LabelCell: UICollectionViewCell, NibReusable { … }, telling me Redundant conformance of 'LabelCell' to protocol 'Reusable'… but this one makes sense (since indeed now UICollectionViewCell is already Reusable and NibReusable is a typealias for NibLoadable & Reusable, so the compiler is right here)
  • But I don't reproduce the warning you have about UICollectionViewCell already conforming to Reusable in UIKit though.

What version of Xcode and Swift are you using? Maybe the difference is somewhere there?

Did you try to add the name of the Reusable module (and not you module) before Reusable (because the Reusable protocol comes from the Reusable framework/module, not your module)? Like extension UICollectionViewCell: Reusable.Reusable {}?


Also, side note and personal point of view: I also personally don't recommend making UICollectionViewCell directly conform to Reusable, because it has the potential risk of making collection view cells even not from your app conform to it, like cells used by other frameworks in your app, for example etc. So I prefer to mark only your own cell classes as conforming. I know it can be repetitive, but I prefer explicit conformance than global implicit conformance that could potentially "leak" to more parts of your app that you intend to. See also the notes in the README in this paragraph:

In case your custom UIViewController, UITableViewCell, etc… is intended to be subclassed and be the parent class of many classes in your app, it makes more sense to add the protocol conformance (StoryboardBased, Reusable, …) to the child classes (and mark them final) than adding the protocol on the parent, abstract class.

from reusable.

danmartyn avatar danmartyn commented on July 20, 2024

Using Xcode 9.2 and Swift 4.0. I hadn't thought about making all cells Reusable being a bad idea before though, and you raised a good point. I've gone back and removed those extensions, and instead made my base classes all conform to Reusable, since I know all my custom cells will be subclassing the base views anyways, and this fixes the warning. Thanks for the help!

from reusable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.