O'Reilly logo

iOS® 8 for Programmers: An App-Driven Approach with Swift™, Third Edition by Abbey Deitel, Harvey M. Deitel, Paul J. Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.6.7 Global Utility Functions Defined in ViewController.swift

Figure 3.46 contains several global utility functions used throughout class ViewController. Add lines 84–103 after the closing right brace of class ViewController.

  84   // convert a numeric value to localized currency string  85   func formatAsCurrency(number: NSNumber) -> String {                 86       return NSNumberFormatter.localizedStringFromNumber(             87           number, numberStyle: NSNumberFormatterStyle.CurrencyStyle)  88   }                                                                   89   90   // overloaded + operator to add NSDecimalNumbers  91   func +(left: NSDecimalNumber, right: NSDecimalNumber) -> NSDecimalNumber ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required