0

I can't figure this out, referencing this post: Struggling with NSNumberFormatter in Swift for currency

I can't get a reference to NSNumberFormatter...i.e. I can't call any methods on formatter? (the below throws an error of expected declaration)

import Foundation

class CurrencyFormatter {

    var price = 100

    var formatter = NSNumberFormatter()
    formatter.numberStyle = .CurrencyStyle
    formatter.stringFromNumber(price)



}

enter image description here

Community
  • 1
  • 1
GarySabo
  • 5,806
  • 5
  • 49
  • 124
  • What part of this is not working? I pasted it in to the Playground and it worked fine? What is your error? – Will M. May 08 '15 at 16:47
  • I added a screenshot...I'm in a new file and a separate class, is there something else I need to import? – GarySabo May 08 '15 at 16:50
  • Oh, you probably need to operate on the formatter stuff in a function, not just sitting in the class. I posted some code below – Will M. May 08 '15 at 16:52

1 Answers1

0
class CurrencyFormatter {

    var price = 100

    var formatter = NSNumberFormatter()

    init() {
        formatter.numberStyle = .CurrencyStyle
        formatter.stringFromNumber(price)
    }
}
Will M.
  • 1,864
  • 17
  • 28