Reputation: 1342
I have a float (rate
) that can be set by the user for this app. I would like to keep this variable persistent, so I would like to use the @AppStorage
property wrapper. The problem I'm having is that @AppStorage("rate) var rate: Float = 0.5
gives No exact matches in call to initializer
. After some brief googling, I learned that you cannot store floats with app storage. Is there a way to work around this?
Upvotes: 2
Views: 1429
Reputation: 30401
Looking at the definition of AppStorage
you can find the following allowed types:
Bool
Int
Double
String
URL
Data
Int
raw valueString
raw valueBool?
Int?
Double?
String?
URL?
Data?
Int
raw valueString
raw valueSo you should probably use Double
, rather than Float
(you shouldn't really use Float
anyway, since it's 32-bit rather than 64-bit).
Upvotes: 2