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! While you're at it, check out some resources Treehouse students have shared here.

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

Jose Portuondo-Dember
seal-mask
.a{fill-rule:evenodd;}techdegree
Jose Portuondo-Dember
iOS Development Techdegree Student 5,275 Points

Help me fix this error: "Bummer! Make sure you're adding an add method that takes an Int and returns Int?"

No matter what I try, including straight up copy-pasting solutions that others have posted success with, I keep getting the same error: "Bummer! Make sure you're adding an add method that takes an Int and returns Int?"

my code works fine in playground, and returns an Int? wrapped in optional(). I am at my wit's end. Any suggestions are welcome.

types.swift
// Enter your code below
extension String {
    func add(_ value: Int) -> Int? {
        guard let originalStringAsInteger = Int(self) else {
            return nil
        }
            return originalStringAsInteger + value)


    }
}

2 Answers

andren
andren
28,558 Points

The issue is the external parameter name you have added, the instructions does not ask you to name the parameter _ externally. In the example provided value is the parameter name used when calling the method.

If you remove the external name like this:

extension String {
    func add(value: Int) -> Int? {
        guard let originalStringAsInteger = Int(self) else {
            return nil
        }
        return originalStringAsInteger + value
    }
}

Then the code will be accepted.