Swift 3 - How to write functions with no initialisers like the new UIColors?

前端 未结 6 645
再見小時候
再見小時候 2021-01-18 17:31

In previous versions of swift, you would get the colour white like this UIColor.whiteColor()

However, in Swift 3, you get the colour white without initi

6条回答
  •  旧时难觅i
    2021-01-18 18:03

    They are properties, not functions.

    import UIKit
    
    extension UIColor {
      // Read-only computed property allows you to omit the get keyword
      static var custom: UIColor { return UIColor(white: 0.5, alpha: 1) }
    }
    

提交回复
热议问题