2016-05-24 7 views
0

私はUtilクラスをヘルパークラスとしてswiftで使用しています。関数のほかに、カスタムカラーでいくつかの定数を実装したいと思っています。Swiftのグローバル定数のクラス内の構造体

このようにStructを使用するのは正しいですか?

class Util: NSObject { 

struct Colors { 
    static let white = UIColor(red: 1, green: 1, blue: 1, alpha: 1) 
    static let orangeCantaloupe = UIColor(red: 1, green: 204/255, blue: 102/255, alpha: 1) 
    static let greyMercury = UIColor(red: 230/255, green: 230/255, blue: 230/255, alpha: 1) 
    static let greyMagnesium = UIColor(red: 179/255, green: 179/255, blue: 179/255, alpha: 1) 

} 

class func anyFunction() { 

....... 
} 
} 
+0

'/ 255'をすべて抽象化する' UIColor'を生成するヘルパー関数を作成する必要があります – Alexander

答えて

-1

これは列挙の仕事です。

struct Colors { 
    case white(UIColor(red: 1, green: 1, blue: 1, alpha: 1)) 
    case orangeCantaloupe(UIColor(red: 1, green: 204/255, blue: 102/255, alpha: 1)) 
    case greyMercury(UIColor(red: 230/255, green: 230/255, blue: 230/255, alpha: 1)) 
    case greyMagnesium(UIColor(red: 179/255, green: 179/255, blue: 179/255, alpha: 1)) 
} 
関連する問題