Much nicer.. but the same outcome - warning based on the value of hammers. Same, even if I use a variable to load hammers, as Ronald suggested.
On Jun 4, 2014, at 23:36, Robert Lockstone < email@hidden> wrote:
Qualifier: Haven’t read much about Swift and don’t have it set up locally.
Can’t you just do:
let hammerTitle = (hammers == 1) ? " hammer" : " hammers"
Rob On Jun 4, 2014, at 13:17 , Ronald Lingl < email@hidden> wrote: What am I missing here? The condition is if hammers equals 1, which it does. So the statement should always be executed. That is why he gets the correct result of hammer in the output.
> If hammers does not equal 1, it also works, but I get a compiler warning: “Will never be executed” on the hammerTitle = " hammer" statement.
Makes sense. If you hard-coded the number of hammers (and there's no place where hammers could possibly change), then there are no code paths that could result in that if block being executed.
|