I realized after sending that 100 won’t be correct, so you’ll need
something like this:

batteryIcon.image = UIImage(named: "\(min(10, (_myBatteryLevel % 10) + 1))")


Jeff Kelley

slauncha...@gmail.com | @SlaunchaMan <https://twitter.com/SlaunchaMan> |
jeffkelley.org

On Fri, Mar 10, 2017 at 10:50 AM, Eric E. Dolecki <edole...@gmail.com>
wrote:

> Thank you!
>
> On Fri, Mar 10, 2017 at 10:48 AM Jeff Kelley <slauncha...@gmail.com>
> wrote:
>
>> Something like this should work:
>>
>> batteryIcon.image = UIImage(named: "\((_myBatteryLevel % 10) + 1)")
>>
>>
>> Jeff Kelley
>>
>> slauncha...@gmail.com | @SlaunchaMan <https://twitter.com/SlaunchaMan> |
>> jeffkelley.org
>>
>> On Fri, Mar 10, 2017 at 10:41 AM, Eric E. Dolecki <edole...@gmail.com>
>> wrote:
>>
>> I have this super simple code, but I'd like to whittle it down to
>> something
>> a lot smaller - basically looking for multiples of 10 (100-0) for a value.
>> I need coffee, what's a great way to do this in Swift 3?
>>
>> if _myBatteryLevel >= 90 {
>>             batteryIcon.image = UIImage(named: "10")
>>         } else if _myBatteryLevel >= 80 {
>>             batteryIcon.image = UIImage(named: "9")
>>         } else if _myBatteryLevel >= 70 {
>>             batteryIcon.image = UIImage(named: "8")
>>         } else if _myBatteryLevel >= 60 {
>>             batteryIcon.image = UIImage(named: "7")
>>         } else if _myBatteryLevel >= 50 {
>>             batteryIcon.image = UIImage(named: "6")
>>         } else if _myBatteryLevel >= 40 {
>>             batteryIcon.image = UIImage(named: "5")
>>         } else if _myBatteryLevel >= 30 {
>>             batteryIcon.image = UIImage(named: "4")
>>         } else if _myBatteryLevel >= 20 {
>>             batteryIcon.image = UIImage(named: "3")
>>         } else if _myBatteryLevel >= 10 {
>>             batteryIcon.image = UIImage(named: "2")
>>         } else if _myBatteryLevel >= 0 {
>>             batteryIcon.image = UIImage(named: "1")
>>         }
>>
>> Thanks for thinking about my lame code.
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/cocoa-dev/slaunchaman%40gmail.com
>>
>> This email sent to slauncha...@gmail.com
>>
>>
>>
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to