• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Swift question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Swift question


  • Subject: Re: Swift question
  • From: David Delmonte <email@hidden>
  • Date: Wed, 04 Jun 2014 23:46:15 +0300

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.


From: Avery Pierce <email@hidden>
To: David Delmonte <email@hidden>
Cc: Xcode Users <email@hidden>
Sent: Wednesday, June 4, 2014 12:08 PM
Subject: Re: Swift question

> 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.


On Wed, Jun 4, 2014 at 1:31 PM, David Delmonte <email@hidden> wrote:


Thanks for the fast responses.

I am almost there..

If I do this (thanks Carl):

var hammerTitle = " hammers"
        
        if hammers == 1  {
            hammerTitle = " hammer"
        }
        let toolSummary = "I have \(nails) nails and \(hammers)" + hammerTitle
        
        println("toolSummary: \(toolSummary)")
        println()

I do get the desired result if hammers does equal 1. If hammers does not equal 1, it also works, but I get a compiler warning: “Will never be executed” on the  hammerTitle = " hammer" statement. It’s the same if I redeclare hammerTitle in the if statement..

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: Swift question (From: Carl Leiby <email@hidden>)
 >Re: Swift question (From: David Delmonte <email@hidden>)
 >Re: Swift question (From: Avery Pierce <email@hidden>)
 >Re: Swift question (From: Ronald Lingl <email@hidden>)
 >Re: Swift question (From: Robert Lockstone <email@hidden>)

  • Prev by Date: Re: Swift question
  • Next by Date: Swift JIT
  • Previous by thread: Re: Swift question
  • Next by thread: Re: Swift question
  • Index(es):
    • Date
    • Thread