monekypox121 monekypox121 - 3 years ago 278
Swift Question

Extension: error use of undeclared type

I am new to swift, and I would like to create an extension of the Dog class:

class ViewController: UIViewController {

override func viewDidLoad() {

public class Dog {
var name = "Timmy"

extension Dog {
func description() -> String {
return "A dog named \("

I thought extensions go at the way bottom, can someone help me with this?

Answer Source

Your Dog class is "hidden" inside your ViewController class. Declare it at top level or refer to it as ViewController.Dog.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download