GithubHelp home page GithubHelp logo

Comments (6)

AliSoftware avatar AliSoftware commented on July 20, 2024

@rollandjb Are you sure about this?

I just tested this in a playground, so it seems to work as expected even with Self:

protocol Reusable {
  static var reusableIdentifier: String { get }
}

extension Reusable {
  static var reusableIdentifier: String {
    return String(Self)
  }
}

class ParentView: Reusable {}
class ChildView: ParentView {}

let ri = ChildView.reusableIdentifier
print(ri) // prints "ChildView", as expected

from reusable.

rollandjb avatar rollandjb commented on July 20, 2024

Yes I am, as the following playground snippet shows. Of course, my explanation may be wrong.

protocol Reusable {
    static var reusableIdentifier: String { get }
}

extension Reusable {
    static var reusableIdentifier: String {
        return String(Self)
    }
}

class Cell {
    required init() {}
}

class ParentView:Cell, Reusable {}
class ChildView: ParentView {}

let ri = ChildView.reusableIdentifier
print(ri) // prints "ChildView", as expected

class TableView {}

extension TableView {
    func dequeue<T: Cell where T: Reusable>() -> T {
        print(T.reusableIdentifier)

        return T()
    }
}

let tableView = TableView()

tableView.dequeue() as ChildView // prints ParentView for Self, ChildView for self

from reusable.

AliSoftware avatar AliSoftware commented on July 20, 2024

Ok, talked to someone working on the Swift compiler and it appears that it's actually a bug

https://twitter.com/jckarter/status/691643221487693824

Not sure if the right solution is to use self though, probably is but before making that change I want to investigate more and especially ensure that it won't have side-effects. Like for some edge cases like when you customize the description or debugDescription of the class or the CustomMirror etc.

I definitely have to add Unit Tests to that pod anyway, might be a good occasion to do so.

from reusable.

rollandjb avatar rollandjb commented on July 20, 2024

That's interesting. And of course you are right, customising description and debugDescription could cause trouble! In the mean time it works for me where I derive cells from a base cell.

Furthermore, my explanation was inaccurate!

from reusable.

AliSoftware avatar AliSoftware commented on July 20, 2024

Bug reported on the Swift bug tracker: https://bugs.swift.org/browse/SR-617

Will try to add unit tests and see how we could workaround this (using self maybe as you suggested, but have to confirm with tests it works in all conditions first) soon. (Don't hesitate to make a PR to add some Unit Tests too, especially test cases matching your use case and demonstrating the issue)

from reusable.

AliSoftware avatar AliSoftware commented on July 20, 2024

Closed by 5cc715c

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.