Uploaded image for project: 'Swift'
  1. Swift
  2. SR-1479

UIColor Float-based initializer shouldn't be there

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Duplicate
    • Component/s: None
    • Labels:
      None
    • Environment:

      May 3rd dev toolchain

      Description

      Discovered on the Swift-User list that UIColor in the most recent May 3rd toolchain supports initializers for both Float and CGFloat. Which is odd: Bit of a problem because Xcode complains about an “Ambiguous use of init(red:green:blue:alpha”. No kidding. So right now, you have to cast everything, e.g.

      let color = UIColor(red: CGFloat(0.5), green: CGFloat(0.5), blue: CGFloat(0.5), alpha: CGFloat(1.0))

      Or you can do something really stupid like this:

      {{extension Double {
      var cg: CGFloat

      { return CGFloat(self) }

      }

      class ViewController: UIViewController {
      override func viewDidLoad()

      { super.viewDidLoad() let c = UIColor(red: 0.5.cg, green: 0.5, blue: 0.5, alpha: 0.5) }

      }}}
      It works but ew. Who ever uses Float with UIColor to begin with and why did this pop up in the latest build? Is it part of the Cocoa auto-migration thing?

      Can you please take it out? Thanks.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              erica erica sadun
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: