我有一个大型数据模型,其中的对象需要可以进行比较。为此,我向他们添加了hashValue getter,如下所示:
var hashValue:Int
{
let h1 = (31 &* id.hashValue)
&+ caseID.hashValue
&+ statusID.hashValue
&+ assignedToID.hashValue
let h2 = h1 &+ runID.hashValue
&+ templateID.hashValue
&+ typeID.hashValue
&+ priorityID.hashValue
let h3 = h2 &+ milestoneID.hashValue
&+ customOS.description.hashValue
&+ title.hashValue
&+ estimate.hashValue
&+ estimateForecast.hashValue
let h4 = h3 &+ refs.hashValue
&+ customAutomated.hashValue
&+ customPreconds.hashValue
let h5 = h4 &+ customSteps.hashValue
&+ customExpected.hashValue
let h6 = h5 &+ customMission.hashValue
&+ customGoals.hashValue
&+ customLabel.description.hashValue
let h7 = h6 &+ customSteps.hashValue
&+ customStepsSeparated.description.hashValue
return h7
如果模型对象具有太多属性,我将其分解为如上所述。这很顺利,直到我用相同的处理方法覆盖了几个模型类。现在约。编译时可编辑的10个模型类从1分钟到10分钟,之后编译完全失败并出现以下错误:
Error:unable to execute command: Killed: 9
Error:compile command failed due to signal 9 (use -v to see invocation)
Error:Build failed with 0 errors and 97 warnings in 14m 34s 489ms
我该怎么做才能防止这种情况发生?我使用的是Swift 4和Xcode 9.2。