-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Protocols need to use String(self) rather than String(Self) #2
Comments
@rollandjb Are you sure about this? I just tested this in a playground, so it seems to work as expected even with 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 |
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 |
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 I definitely have to add Unit Tests to that pod anyway, might be a good occasion to do so. |
That's interesting. And of course you are right, customising Furthermore, my explanation was inaccurate! |
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 |
Closed by 5cc715c |
The use of Self fails in the presence of subclassed cells because String(Self) refers to the class directly conforming to the protocol, while String(self) refers correctly to the class of the instance.
The text was updated successfully, but these errors were encountered: