Swift execute code after return, unbelievable!!

I created a tableview and there is a toggle in a cell, I click the toggle there will be an function in the cell's protocol, and in the implement of the function I have a logic like this: 
Code Block
extension NewPortfolio: PortfolioBasicInfoCellProtocol {
    func privacyButtonEvent() {
        if !privacyModeOn {
            return
            print("what?")
//            basedOnFiatCur.toggle()
//            let preferences = UserDefaults.standard
//            preferences.set(basedOnFiatCur, forKey: "basedOnFiatCur")
//            NotificationCenter.default.post(name: .toggledBaseCurFromModal, object: nil)
//            UISelectionFeedbackGenerator().selectionChanged()
//            mainTable.reloadData()
        }
    }
}

then compiler print:
what?
The print function after the return is executed! can't believe this anybody know why? or this is a bug of apple?

Answered by OOPer in 658442022
Compiling the shown code, Xcode showed this warning:
Code Block
Expression following 'return' is treated as an argument of the 'return'


The two line is treated as:
Code Block
return print("what?")


In Swift, return statement in a Void function can return only one specific value Void().
(An instance of Void, which is equivalent as the empty tuple ().)
And the return type of print is Void, which means it returns Void().

Thus, the result of calling print("what?") can be a return value of Void function as you see.
Accepted Answer
Compiling the shown code, Xcode showed this warning:
Code Block
Expression following 'return' is treated as an argument of the 'return'


The two line is treated as:
Code Block
return print("what?")


In Swift, return statement in a Void function can return only one specific value Void().
(An instance of Void, which is equivalent as the empty tuple ().)
And the return type of print is Void, which means it returns Void().

Thus, the result of calling print("what?") can be a return value of Void function as you see.
Swift execute code after return, unbelievable!!
 
 
Q