Swift 获取返回函数范围外布尔值的函数的值

Swift 获取返回函数范围外布尔值的函数的值,swift,swift3,Swift,Swift3,我有一个扣除硬币的功能 func deductCoins() -> Bool { if price > coins { label.text = String("You dont have enough coins") self.view.addSubview(label) return false } if coins >= price {

我有一个扣除硬币的功能

func deductCoins() -> Bool {

        if price > coins {
            label.text = String("You dont have enough coins")
            self.view.addSubview(label)
            return false
        }
        if coins >= price {
            coins = coins - price
            UserDefaults.standard.set(coins, forKey: "Coins")

            //this stuff has to do with the purchasing
            BackBtn.removeFromSuperview()
            PurchaseBtn.removeFromSuperview()
            label.removeFromSuperview()
            image.removeFromSuperview()
            return true
        }

        return true
    }
当用户在我的游戏中“购买内容”时,此函数用于从UserDefaults值“coins”中扣除硬币(即名称),我需要一种方法来测试此函数根据用户的硬币数量与物品价格(如代码中所述)是否返回true或false但我需要测试它是否在函数范围外返回true或false

编辑


问题现在更清楚了(p.S.当我编写原始时,我很累了,它的工作方式与任何其他具有返回值的函数相同

let deducted = deductCoints()
if deducted {
    //function returned true
} else {
   //function returned false
}
如果不想存储返回值,只需检查一次,甚至不需要将其存储在变量中

if deductCoins() {
    //function returned true
} else {
   //function returned false
}

有关函数的更多信息,请查看

什么“效果很好”和什么是“我需要确定多个值是否已解锁”的意思?问题完全不清楚..一个人可以得到你在问什么我已将问题更改为更清楚