Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift:更改结构代码时生成时间较慢_Swift_Xcode_Compilation - Fatal编程技术网

Swift:更改结构代码时生成时间较慢

Swift:更改结构代码时生成时间较慢,swift,xcode,compilation,Swift,Xcode,Compilation,tl;dr 将代码更改应用于常用的struct会导致生成时间非常缓慢。这能避免吗 我有一个相当大的Swift项目(Xcode 9.2),我使用结构来保存应用程序中使用的所有样式信息(颜色、间距等),比如: struct Style { var iconColor: UIColor = .darkGray var lightTextColor: UIColor = .gray // ... and many more properties ... static var defa

tl;dr

将代码更改应用于常用的
struct
会导致生成时间非常缓慢。这能避免吗


我有一个相当大的Swift项目(Xcode 9.2),我使用
结构来保存应用程序中使用的所有样式信息(颜色、间距等),比如:

struct Style {
  var iconColor: UIColor = .darkGray
  var lightTextColor: UIColor = .gray
  // ... and many more properties ...

  static var defaultStyle: Style { 
    return Style() 
  }

  static var fancyStyle: Style {
    var style = Style()
    // ... override style props for more fancyness ...
    return style
  }
}
每个视图控制器(项目中大约有30个VCs,都是用代码创建的——不使用故事板)都有一个
Style
实例,并在呈现其UI时使用它:

class MyViewController: UIViewController {
  var style = Style.defaultStyle // can be overridden by creator of the VC
  override func viewDidLoad() {
    super.viewDidLoad()
    myLabel.textColor = style.lightTextColor
  }
}
这非常有效,只允许在一个地方更改设置,而不会用全局常量污染名称空间

但是,我注意到,当在
结构中更改属性的默认值时,编译时间会急剧增加,Xcode基本上执行完全重建。例如,将上述
Style.lightTextColor
的定义更改为
var lightTextColor:UIColor=.green
将导致与项目完全重建相当的构建时间。但是,如果我在使用它的地方直接更改了值;e、 g.在视图控制器中:
myLabel.textColor=.green
,项目构建速度非常快

是否有解决方案,最好通过配置编译器来完成。。。在这种情况下工作少了