lolgear
(Dmitry Lobanov)
September 24, 2018, 6:41am
1
Well, I have an exercise with nested classes.
Suppose "architecture" - a domain-driven Developer module that contains developer settings for an app.
However, this module is not extracted into target.
Next, follow nesting:
Developer module has settings. Settings can be presented in ViewModel that could create ViewController which has several cells to modify settings.
Next, try to extended nested class which has 3 or 4 nesting like Cell or ViewController.
extension Developer.Settings.ViewModel.ViewController.CellWithSwitch {
// Some methods.
func example() {
self // <- self is error type here.
}
}
jeremyp
(Jeremy Pereira)
September 24, 2018, 9:41am
2
So I did this in a Playground (Xcode 10, Swift 4.2)
struct Developer
{
struct Settings
{
struct ViewModel
{
struct ViewController
{
struct CellWithSwitch
{
var a: String = "Hi"
}
}
}
}
}
extension Developer.Settings.ViewModel.ViewController.CellWithSwitch
{
func example()
{
let y = self.a
print("\(y)") // <- self is error type here.
}
}
let x = Developer.Settings.ViewModel.ViewController.CellWithSwitch()
x.example()
No error and "Hi" was printed as expected.
lolgear
(Dmitry Lobanov)
September 24, 2018, 10:19am
3
Try to put them in separate files.
jeremyp
(Jeremy Pereira)
September 24, 2018, 1:13pm
4
When I try to compile your code I get an error on the definition of Developer.Settings.ViewModel
unless I move it into the same file as the definition of Developer.Settings
. It looks like a compiler bug to me.
jrose
(Jordan Rose)
September 24, 2018, 4:40pm
5
This sounds like SR-631 . Can you try with a snapshot from the "master" branch on Swift.org - Download Swift ?