W
W
wer_erwq2021-08-29 14:29:27
Swift
wer_erwq, 2021-08-29 14:29:27

How to count an example in swift written to a variable?

Variable of type String
var a = "1+2"
​​How to calculate

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
wer_erwq, 2021-08-30
@wer_erwq

var numericExpression = "4 + 3 - 2"
let expression = NSExpression(format: numericExpression)
var result = expression.expressionValueWithObject(nil, context: nil) as NSNumber

B
briahas, 2021-08-29
@briahas

This is an Assignment, not a Question. Try to implement it yourself (in the playground - as easy as shelling pears). If you run into misunderstandings about the programming part - come and ask.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question