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:
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?
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?
Compiling the shown code, Xcode showed this warning:
The two line is treated as:
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.
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.