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

@State vs @SwiftUI.State

Forums > SwiftUI

I have this line:

@State var isModalSheetShown: Bool = false

which gives this error in Xcode 12, Beta 4:

Generic enum 'State' cannot be used as an attribute.

If I prefix State with "@SwiftUI" the error goes away:

@SwiftUI.State var isModalSheetShown: Bool = false

Anybody know why this is? Is it just an oddity of the beta version that should go away when it's fully released? I do have import SwiftUI at the top of the file so I don't think it's caused by a missing import.

2      

Do you have an enum called State anywhere in your code?

3      

Dang, that is impressive intuition! It's not my code per se, but Khanlou's Promise library that I'm using. I searched in there, and sure enough, there's an enum called State. Thanks so much for sleuthing that out!

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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.