TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Almost have it

Forums > Swift

I almost have for the function descnedant. Could some one please help? Here is my code.

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    func descendant(_ first: Int, _ rest: Int) -> Any? {
        print("\(first) \(rest)")
        return descendant(_:_:)
    }
    descendant(4, 9)

}

}

3      

Not really sure what it is you're trying to do here. Can you clarify?

3      

What I'm trying to do is print out the numbers of the descendants.

I think I found the soultion.

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    func descendant(_ first: Int, _ rest: Int) -> Any? {
        print("\(first) \(rest)")
        return descendant(_:_:)
    }
    print(descendant(4, 9)!)

}

}

The output that I see is: 4 9 (Function) could anyone tell me if this would be correct?

3      

If all you want to do is print out the numbers, then this will work:

override func viewDidLoad() {
    super.viewDidLoad()

    func descendant(_ first: Int, _ rest: Int) {
        print("\(first) \(rest)")
    }
    descendant(4, 9)

}

You don't need to return anything from descendant since you handle the printing inside that function.

3      

Thank you for your help. It worked like a charm.

3      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.