/* Colocando a função para funciona */ func testePrimo(_ numero: Int) -> Bool { for i in 2..<numero { if numero % i == 0 { return false } } return true } testePrimo(43) testePrimo(42)
/* Função com opcional */ func nome(valor: String?) { guard let valor = valor else { print("Nome não identificado") return } print(valor) } nome(valor: "Janine") nome(valor: nil)
/* Indo ao restaurante */ func calculaConta(_ totalDespesa: Double, _ numeroPessoas: Int) -> Double { var totalComTaxa = totalDespesa * 1.1 return totalComTaxa / Double(numeroPessoas) }
var totalParaCadaPessoa = calculaConta(120, 4) print(totalParaCadaPessoa)