Home > Mobile >  SwiftUI Storing field entry as a double or integer
SwiftUI Storing field entry as a double or integer

Time:04-27

I'm trying to store a user's text field entry as a number so it's easier to work with in formulas. I thought I was being slick by storing it as a string, but now using the input in mathematical formulas is becoming a real pain in the neck. It should be noted that these field entries are being stored in CoreData currently as a string entity.

Here's an MRE of one of my fields:

import SwiftUI

struct EntryMRE: View {
    @Environment(\.managedObjectContext) private var viewContext
    
    @State private var showingResults: Int? = 1
    
    @FocusState private var isTextFieldFocused: Bool
    @State var isDone = false
    
    @State var isSaving = false //used to periodically save data
    @State var saveInterval: Int = 5 //after how many seconds the data is automatically saved

    //DataPoints Chemistry
    @State var potassium = ""
  
    
    var body: some View {
        List {
            Section(header: Text("           
  • Related