Question: Is there a way to conform to a Swift protocol using default values?

The following example results in a `Type 'FunExample' does not conform to protocol 'Example'`:

```
protocol Example {
    func doSomething(with: String)
}

class FunExample: Example {
    func doSomething(with: String, butMakeItFun: Bool = true) {
        // implementation
    }
}

```

...even though I actually implicitly conform since this is identical to:

```
protocol Example {
    func doSomething(with: String)
}

class FunExample: Example {
    func doSomething(with: String) {
        self.doSomething(with: with, butMakeItFun: true)
    }
    func doSomething(with: String, butMakeItFun: Bool) {
        // implementation
    }
}

```

Is there a cleaner way to provide conformance using default values? Or am I missing something conceptually when I say that the first example *should* also pass conformance?

To clarify: I understand *why* the error is produced. My question is more conceptual (whether Swift *should* work this way) and whether there is an elegant way around it.

Answer: 
You can go with `extension` for the more cleaner way! Make an `extension` with the same `protocol` methods and pass the default values which you want. Let's say:

```
protocol Example { //Main Protocol
    func doSomething(with: String, butMakeItFun: Bool)
}

extension Example { //Make to pass the default values if you want
    func doSomething(with: String, butMakeItFun: Bool = false) {
        return doSomething(with: with, butMakeItFun: butMakeItFun)
    }
}

class FunExample: Example { //Protocol Acceptance
    func doSomething(with: String, butMakeItFun: Bool) {
        debugPrint("\(with)")
        debugPrint(butMakeItFun)
    }
}

```

You can call it via following ways:

1. `FunExample().doSomething(with: "Hello Default Values...")`
2. `FunExample().doSomething(with: "..........", butMakeItFun: true)`

> 
> Update
> 
> 
> 

So based on your comment, here is what I have came up! You can take a variable under the `protocol` which surely says `true` or `false` as a default implementation and later-on you can change it in your `class`.

```
protocol Example {
    var isFun: Bool {set get}
    func doSomething(with: String)
}

class FunExample: Example {

    //var isFun: Bool = false - In case you want to change value

    func doSomething(with: String) {
        doSomething(with: with, butMakeItFun: isFun)
    }

    func doSomething(with: String, butMakeItFun: Bool) {
        debugPrint(with)
        debugPrint(butMakeItFun)
    }
}

extension Example {
    var isFun: Bool {
        get { return true /* Your Default Value */ } set {}
    }
}

```
As your example code is written, your FunExample does not conform because it does not have a function `func doSomething(with: String)`.

`func doSomething(with: String)` and `func doSomething(with: String, butMakeItFun: Bool)` are not the same. So it doesn't conform. 

When you add the following code it will conform

```
func doSomething(with: String) {
    self.doSomething(with: with, butMakeItFun: true)
}

```

I would provide a default implementation of doSomething(with: String) and then 'decorate' it where needed.

```
protocol Example {
    func doSomething(with: String)
}

extension Example {
    func doSomething(with text: String) {
        print(text)
    }
}

class FunExample: Example {
    func doSomething(with: String, butMakeItFun: Bool) {

        if butMakeItFun() {
          playTheSound()
          releaseBalloons()
        }

        return doSomething(with: String)
    }
}

```