Swift - Structs - Static var vs static func

时间:2016-10-22 10:24:51

标签: ios swift struct

我一直习惯于创建一个Config文件,我在其中声明了一些我需要为整个应用程序重用的东西(颜色,其他一些特定的东西......)。在Swift中,事物与Objective C不同,所以我决定使用结构。但现在我很难理解这两种方法中哪一种更好用:

struct Config {

        struct Colors {

            static func main () -> UIColor {
                return UIColor.red
            }

            static func secondary () -> UIColor {
                return UIColor.yellow
            }

            static let mainVar = UIColor.red
            static let secondaryVar = UIColor.yellow
        }
    }

两者之间的区别很明显:一些是功能(静态),另一些是变量。哪一种是提供此类信息的正确方法(不需要设置参数的信息)?

0 个答案:

没有答案
相关问题