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

SOLVED: Wrong version of Xcode/Swift or am I missing something?

Forums > SwiftUI

Hi guys,

New to SwiftUI/coding in general, and was wondering if someone could help me.

Going through the 100 Days of SwiftUI, everything was fine with the Playground work, but I've encountered some problems with Project 1 and 2 with some of the code not building on my SwiftUI. For example the code below for Project 1 doesn't seem to work, and the error below it is given.

TextField("Amount", value: $checkAmount, format: .currency(code: Locale.current.currencyCode ?? "USD"))

Cannot infer contextual base in reference to member 'currency'. Extra argument 'format' in call Missing argument for parameter 'formatter' in call Insert ', formatter: <#Formatter#>'

I managed to get around this (kind of) with 'NumberFormatter()', but I am now struggling with Project 2 as I can't do simple button styling such as:

VStack {
    Button("Button 1") { }
        .buttonStyle(.bordered)
    Button("Button 2", role: .destructive) { }
        .buttonStyle(.bordered)
    Button("Button 3") { }
        .buttonStyle(.borderedProminent)
    Button("Button 4", role: .destructive) { }
        .buttonStyle(.borderedProminent)
}

I am using a MacBook Pro 2012 and running Catalina 10.15.7 which means I can only run Xcode 12.1, but looking online I can't seem to find any reference to styling such as '.bordered' not being available on this version and so wondering if I'm missing something obvious.

Looking to upgrade my MacBook at the end of the month but would like to continue as much as possible up until then.

Any help would be appreciated, thank you.

1      

Nathan jumps directly into the deep end:

I am running Catalina 10.15.7 meaning I can only run Xcode 12.1, but looking online I can't seem to find any reference to styling such as '.bordered' not being available

I found this reference in Apple's documentation. If you look at the rightmost panel, you'll see Availability is iOS 15.0+

In your Swift project, you can set the target OS version for the application you're developing. Check that to see if iOS 15.0 or higher is an option.

See-> Apple: Bordered Button Style

I wrote a similar response last year for a similar problem. Maybe this helps?

See-> Let's Play a Game

1      

Nathan jumps directly into the deep end:

Sorry, this went well above my head.

I found this reference in Apple's documentation. If you look at the rightmost panel, you'll see Availability is iOS 15.0+

Ah yes, thank you for that, I see now! Yes unfortunately iOS 15 is not available, 14.1 is my latest version - guess I need to upgrade then!

Thanks for your response, appreciate it.

1      

Nathan jumps directly into the deep end:

It the vast swimming pool of problems that plague developers, you "jumped into the deep end" and found a difficult one!

Some problems might be easy to fix, replacing "var" with "let", using == rather than =. These might be "shallow end" problems.

Come for the Swift discussion, get a free colloquialism lesson.

1      

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.