 # IOS Programming The Big Nerd Ranch Guide 6th Ed - Page 81

This is in page 81 give me an error as in the screenshot attached , What is that

``````Let numberFormatter: NumberFormatter = {
/* IOS Programming The Big Nerd Ranch Guide 6th Ed - Page 81: here you are using a closure to instantiate the number formatter. You are creating a Numberformatter with the .decimal style and configuring it to display no more than one the fractional digits. You will learn more about this in your syntax for declaring properties in chapter 16. */
let nf = NumberFormatter()
nf.numberStyle = .decimal
nf.minimumFractionDigits = 0
nf.maximumFractionDigits = 1
return nf
}()``````
``````// IOS Programming The Big Nerd Ranch Guide 6th Ed - Page 81:
// Numbers formatters
// in the reminder of this chapter, we will update worldTrotter to address two issues:
// 1. you will format the Celsius value to show a position up to one fractional digit,
// 2. and you will not allow the user to tell you in more than one decimal separator.

// use a number formatter to customise the display of a number. There are other formatters for formatting dates, energy, mass, length, measurements, and more

// create a constant number formatter:

/*

Let numberFormatter : NumberFormatter  = {
let nf = NumberFormatter()
nf.numberStyle = .decimal
nf.minimumFractionDigits = 0
nf.minimumFractionDigits = 1
return nf
} ()

// Note that the previous code is not working and give me an error, I search the web and I found this website of documentation of Swift from Apple, at the end of the document of this website https://docs.swift.org/swift-book/LanguageGuide/Initialization.html you will find a subject called setting a default property value with a closure of function, so this is maybe help in understanding the code on page 81 which is the number formatter

*/

/*
// start again with page 81 , after reading the document

Let numberFormatter: NumberFormatter = {
/* IOS Programming The Big Nerd Ranch Guide 6th Ed - Page 81: here you are using a closure to instantiate the number formatter. You are creating a Numberformatter with the .decimal style and configuring it to display no more than one the fractional digits. You will learn more about this in your syntax for declaring properties in chapter 16. */
let nf = NumberFormatter()
nf.numberStyle = .decimal
nf.minimumFractionDigits = 0
nf.maximumFractionDigits = 1
return nf
}()

// the previous try is not working as well */

// I will use my knowledge to recover this problem
// I tried many things which is not working
// then I started write the code as following to make work
// 1. I wrote                  let numberFormatter = NumberFormatter()
// 2. the I change it to       let numberFormatter : NumberFormatter  {
//
//                             }
// 3. then I wrote inside curly brackets this code
//                                   let nf = NumberFormatter()
//                                   nf.numberStyle = .decimal
//                                   nf.minimumFractionDigits = 0
//                                   nf.maximumFractionDigits = 1
//                                   return nf
// 4. then I change it to       let numberFormatter : NumberFormatter  {
//
//                             }()
// 5. then I change it to       let numberFormatter : NumberFormatter = {
//
//                             }()
// Only these steps were working smothly in the code without error

let numberFormatter : NumberFormatter = {
let nf = NumberFormatter()
nf.numberStyle = .decimal
nf.minimumFractionDigits = 0
nf.maximumFractionDigits = 1
return nf
}()``````