Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Intermediate Swift Extensions and Protocols Extending a Native Type

Code doesn't work against verifier but does on Xcode

The code provided doesn't seem to pass the test for the first code challenge of the chapter "Extensions & Protocols" from the Intermediate Swift course, however, it does compile and trying it on Xcode does seem to provide the expected results. Any idea why it isn't working?

// Enter your code below
extension String {
    func add (_ value: Int) -> Int? {
      if let ownValue = Int(self) {
        return ownValue + value
    } else {
        return nil

1 Answer

Clark Reilly
Clark Reilly
6,204 Points

The compiler is really picky about how you name your arguments. You need to get rid of the “_” as the external name. The reason is that the checker is trying to call “1”.add(value: 2) and your code makes the correct syntax “1”.add(2) Which is confusing it.

Edit: fixed spelling error

Thanks, Clark! That was indeed the issue and the change you proposed worked perfectly.