[英]Value of type … has no member
I'm new to Swift and I'm learning it on iTunes U, using a Stanford University course. 我是Swift的新手,正在使用Stanford University课程在iTunes U上学习它。 I'm programming a calculator.
我正在编程一个计算器。 The instructor in the course video has the same code, software and same version of Xcode.
课程视频中的讲师具有相同的代码,软件和相同版本的Xcode。
So here's the code for my ViewController
: 所以这是我的
ViewController
的代码:
@IBAction private func performOperation(sender: UIButton) {
if userIsInTheMiddleOfTyping {
brain.setOperand(displayValue)
userIsInTheMiddleOfTyping = false
}
if let mathematicalSymbol = sender.currentTitle {
brain.performOperation(mathematicalSymbol)
}
displayValue = brain.result
}
The error is in the last sentence: displayValue = brain.result
: 错误在最后一句:
displayValue = brain.result
:
Value of type 'CalculatorBrain' has no value 'result'
类型'CalculatorBrain'的值没有值'result'
This a part of the CalculatorBrain code: 这是CalculatorBrain代码的一部分:
struct PendingBinaryOperationInfo {
var BinaryFunction: (Double, Double) -> Double
var firstOperand: Double }
var result: Double { get { return 0.0 } }
}
So what's the problem? 所以有什么问题?
PS All of the calculator functions aren't set to work yet. PS所有计算器功能尚未设置为起作用。 And the ode that some suggested,
还有一些人建议的颂歌,
displayValue.text = "\(brain.result)"
didn't work at all and it gave me a ton of other errors. 根本不起作用,这给了我很多其他错误。
Here you have a variable result
declared as a property of a struct PendingBinaryOperationInfo
. 在这里,您有一个变量
result
声明为struct PendingBinaryOperationInfo
的属性。 The variable result
is not a property (at least not shown here) of a type CalculatorBrain
wherever that may be. 可变
result
不是任何地方的CalculatorBrain
类型的属性(至少这里没有显示)。 Hence the error. 因此,错误。
You have: 你有:
struct PendingBinaryOperationInfo {
var result: Double
}
When it's looking for: 寻找时:
class CalculatorBrain { // 'class' is just an example
var result: Double
}
brain class don't have result this member, You need to check brain class is that a have result variable. 这个成员没有大脑分类,您需要检查大脑分类是否有一个结果变量。 The result may be private or internal variable so you can not use.
结果可能是私有变量或内部变量,因此无法使用。 It need to change to public member.
它需要更改为公共成员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.