Comments (6)
@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.
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.
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.
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.
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.
Closed by 5cc715c
from reusable.
Related Issues (20)
- getting error on using cellType(for indexPath:)
- Support for new API introduced on iOS 13
- MKMapView support
- Feature request - allow to use UITableViewCell with custom style
- Swift Package Manager: reusable deployment target warning HOT 3
- SPM xibs (Bundle.module) HOT 1
- Xcode 12.5 warnings HOT 2
- Swift tools version update too high, lower version build failed
- UITableViewHeaderFooterView - Warning with NibReusable
- Sure, go ahead!
- ## Summary
- Feature request - access to root xib view
- Support for reusable UITableViewHeaderFooterView subclasses?
- Privacy Manifest
- Swift 5 Support? HOT 2
- Undefined symbols when compiling for unit tests HOT 1
- Xcode 11 beta 4 compiler error HOT 1
- loadNibContent always loads nib named after base class HOT 14
- is there a way to override sceneStoryboard for StoryboardSceneBased HOT 2
- Swift Package Manager HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reusable.