2

Functions are a first-class type. This means that a function can return another function as its value.

func makeIncrementer() -> (Int -> Int) {
func addOne(number: Int) -> Int {
    return 1 + number
}
return addOne
}
var increment = makeIncrementer()
increment(7)

when i implement this i got the following error:

Command /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 254

Also where this functionality can be useful in realtime solutions?

2
  • Your code looks fine. Its working for me without any modification. error is something else Commented Jun 13, 2014 at 7:17
  • @Anil after using M M. answer i am able to solve the problem. Commented Jun 13, 2014 at 7:20

1 Answer 1

3

Per documentation, your function declaration should be like below code, See the parentheses around Int. It indicates the entry parameters.

func makeIncrementer() -> (Int) -> Int
                          ^^^^^^^^^^^^

This funcionality can make it easier to have dynamic code based on a value in run-time.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.