I am new to swift, and I would like to create an extension of the Dog class:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
public class Dog {
var name = "Timmy"
}
}
extension Dog {
func description() -> String {
return "A dog named \(self.name)"
}
}
Your Dog class is "hidden" inside your ViewController class. Declare it at top level or refer to it as ViewController.Dog
.