二元运算符' - '不能应用于两个'[Float]'操作数 - Surge.framework
问题描述:
我最近签出了Surge框架here的新副本。我成功地将它添加到我们的Xcode项目中,但是我收到以下编译错误。二元运算符' - '不能应用于两个'[Float]'操作数 - Surge.framework
Binary operator '-' cannot be applied to two '[Float]' operands
我又试图将它导入到一个新的干净的XCode项目,我仍然得到同样的错误。有没有人看过这个错误,并知道修复?或者这是框架本身的问题。
答
你不能在数组上使用二元运算符,这就是你所拥有的。你可以说因为“浮动”被括号包围。您只能对单个值使用二元运算符。
var myArray = [Float]() //An array(note the brackets)
myArray.append(15) //myArray now contains one value(15), but you still can't use binary operators on it because its an array.
print(myArray + myArray) //Error
print(myArray[0] + myArray[0]) //prints 30, using this syntax "myArray[0]" represents the first object in the array, 30 in this case.
长话短说,切换到非阵列浮动,如果你不需要一个阵列,或直接访问,以使用二进制运算符你对它们的排列在你需要的产品。
+0
感谢您的帮助;但这不完全是我的问题。我知道传统上在阵列上不能使用二元运算符,但Surge框架使用Accelerate框架为[Float]和[Double]重载二元运算符。考虑到这个库是非常发达的(请参阅我的文章中的链接),我担心我的XCode配置的某些元素导致此错误(因为'+',' - ','*'和'/'全部在阵列上工作) –
显然,这是[最近提交](https://github.com/mattt/Surge/commit/f40b3c6a9941dfbc18f4f3bbcdd8a808b0d17286)到Surge库的监督,你已经[已经](https://github.com)/rprechelt /浪涌/提交/ 5f1e87f3ebb7f5df134d055a95a589bd1c18e709)。 –