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 Swift Enums and Structs Enums and their Methods Methods or Member Functions

Adam Short
Adam Short
11,153 Points

Function Inside of Enum will not work (Will not accept values ) but works when placed outside?

So I have created this Enum that contains the following values:

case NewtonSeconds(Int)
case Thrust(Int)
case BurnTime(Int)

However, when I attempt to use this function:

func calculateNSeconds (thrust: Int, burn: Int) -> String {

RocketEngine.Thrust(thrust)
RocketEngine.BurnTime(burn)
var NSeconds = thrust * thrust * burn
RocketEngine.NewtonSeconds(NSeconds)
return "With a burntime of \(burn)s and a thrust of \(thrust)N, we get    a total of \(NSeconds) Newton-Seconds!"

}

I seem to get this error when attempting to run it:

RocketEngine.calculateNSeconds(50, 100) The error: Extra argument in call

Then, if I delete the second value I get this:

Type 'RocketEngine' does not conform to protocol 'IntegerLiteralConvertiable'

What am I doing wrong here? Please help.

1 Answer

Can you post the contents of the whole file please as these snippets don't provide the full picture.

With the full code listing we might be able to figure it out.

Thanks,