I have the following code below and Xcode keeps giving me an error I do not understand how to solve.
class ViewController: UIViewController {
private var manager: Manager?
enum Link {
case faq
case tos
var url: String {
switch self {
case .faq:
return "www.google.com"
case .tos:
return manager!.isFreeUser ? "www.google.com" : "www.duckduckgo.com"
}
}
}
}
The error is:
Instance member ‘manager’ of type 'ViewController' cannot be used on instance of nested type 'ViewController.Link'
You are trying to access a property of the ViewController
class inside a seperate code environment, being the enum Link
.
An easy solution would be to pass your value, in this case manager
as a parameter to the enum like so:
enum Link {
case faq
case tos(Manager)
var url: String {
switch self {
case .faq:
return "www.google.com"
case .tos(let manager):
return manager.isFreeUser ? "www.google.com" : "www.duckduckgo.com"
}
}
}
And whenever you access your enum value, pass in your manager
property.
print(Link.tos(self.manager!).url
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With