UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Day 17

Forums > 100 Days of SwiftUI

The one thing that confuses in the Day 17 of 100 days of SwiftUI is this one:

TextField("Amount", value: $checkAmount, format: .currency(code: "USD"))

2 questions:

1) Without Paul telling us in the lesson how could we learn what type of parameters does TextField accept?

2) "format: .currency" think this is the first time I see this kind of syntax

what is .currency? if it is a method to which class does it belong? So we are providing a method as a value in the format parameter?

Thank you Sergey

3      

Sergey asks:

Without Paul telling us in the lesson how could we learn what type of parameters does TextField accept?

Excellent question!

This is a great lesson for new Swift and SwiftUI programmers. You are progressing from the "show me what to do" phase to the "how can I do this on my own?" phase. Nice!

This is the time for you to learn about SwiftUI documentation.

Here's a link to the documentation about TextField:

Text Field Documentation

It might feel painful, but this is a critical skill to learn.

Scroll throught this documentation until you find the section named "Initializers".

You should see there are several ways to initialize a TextField.

@twostraws used this one:

init<V>(LocalizedStringKey, value: Binding<V>, formatter: Formatter)
Create an instance which binds over an arbitrary type, V. Available when Label is Text.

While in the documentation, if you click on this initializer, you'll see more documentation. This is where you'll see what types of formatters are allowable.

You can follow the Formatter documentation to learn about those! Number formatters, date formatters, measurement formatters, etc.

Read More about Formatters

I would guess that very few Swift programmers have memorized all the methods, and all the options. Consequently, you'll need to learn how to navigate and read the online documentation.

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.