Вот код моего UIButton
@IBAction private func performOperation(sender: UIButton) {
if userIsInTheMiddleOfTyping {
brain.setOperand(displayValue)
userIsInTheMiddleOfTyping = false
}
if let mathematicalSymbol = sender.currentTitle {
brain.performOperation(mathematicalSymbol)
}
displayValue = brain.result
}
Вот моя модель или код контроллера представления
private var operations: Dictionary<String,Operation> = [
"π": Operation.Constant(M_PI),
"e": Operation.Constant(M_E),
"√": Operation.UnaryOperation(sqrt),
"cos": Operation.UnaryOperation(cos),
"✕": Operation.BinaryOperation({ $0 * $1 }),
"÷": Operation.BinaryOperation({ $0 / $1 }),
"+": Operation.BinaryOperation({ $0 + $1 }),
"−": Operation.BinaryOperation({ $0 - $1 }),
"±": Operation.UnaryOperation({ -$0 }),
"=": Operation.Equals,
".": Operation.Period
]
private enum Operation {
case Constant(Double)
case UnaryOperation((Double) -> Double)
case BinaryOperation((Double, Double) -> Double)
case Equals
case Period
}
func performOperation (symbol: String) {
if let operation = operations[symbol] {
switch operation {
case .Constant(let associatedConstantValue):
accumulator = associatedConstantValue
break
case .UnaryOperation(let associatedFunction):
accumulator = associatedFunction(accumulator)
break
case .BinaryOperation(let associatedFunction):
executePendingBinaryOperation()
pending = PendingBinaryOperationInfo(binaryFunction: associatedFunction, firstOperand: accumulator)
break
case .Equals:
executePendingBinaryOperation()
break
case .Period:
displayTextContainsPeriod()
break
}
}
}
private func displayTextContainsPeriod() -> Bool
{
}
Я знаю, чтобы проверить, существует ли существующий период. Мне нужно проверить, содержит ли строка подстроку "." но я не уверен, как получить отображаемый текст в моем func displayTextContainsPeriod