0

I am following a course CS 193P iPhone Application Development - Stanford University. In Lecture 1 of the tutorial the Same code snippet does not show any error. I am trying to display the value of M_PI on UILabel in swift for a Calculator project.But it shows an error 'Missing argument label: StringInterpolationSegment' on Line 4. Below is my code snippet.

  @IBAction func performOperation(sender:UIButton){

     var mathematicalSymbol  = sender.currentTitle!
     if(mathematicalSymbol == "π"){
       display.text = String(M_PI) //display it the variable for UILabel
     }
}

The Function performOperation() is linked to the UIButton with title π.

DEVESH JHA
  • 19
  • 5
  • Take look at [this](http://stackoverflow.com/a/11070469/5654848). – Mtoklitz113 Jun 28 '16 at 16:37
  • #Dershwitz123 I want to display the value not the character. – DEVESH JHA Jun 28 '16 at 16:39
  • The above-linked post explains the error, and a simple solution is to use string interpolation: `display.text = "\(M_PI)"` . You may want to employ a formatter to make sure you only display as many digits as you need. – Brad Larson Jun 28 '16 at 16:42
  • 3
    The linked-to question and its answers are quite old. Actually `display.text = String(M_PI)` should work with the current Xcode 7.3.1. Your Xcode 6.4 is a bit outdated. – Martin R Jun 28 '16 at 16:52
  • @MartinR so how can do it in Xcode 6.4 – DEVESH JHA Jun 28 '16 at 17:05
  • I don't have Xcode 6.4 installed anymore, so I cannot answer that. Are you sure that `let text = String(M_PI)` does not compile? Have you tried `"\(M_PI)"` as suggested in the referenced answers? – Martin R Jun 28 '16 at 17:07

0 Answers0