Advertisement
dartmeadow

Untitled

Aug 6th, 2021
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.74 KB | None | 0 0
  1. //
  2. //  ContentView.swift
  3. //  Cotharticren
  4. //
  5. //  Created by Justin Venable on 8/4/21.
  6. //
  7. import Foundation
  8. import SwiftUI
  9. import CoreData
  10. import Combine
  11.  
  12.  
  13.  
  14. struct ContentView: View {
  15.     @State var orbit: String = ""
  16.    
  17.     let formatter: NumberFormatter = {
  18.             let formatter = NumberFormatter()
  19.             formatter.numberStyle = .decimal
  20.             return formatter
  21.         }()
  22.  
  23.     var body: some View {
  24.         VStack(alignment: .leading) {
  25.         Image("orbit100")
  26.             .clipShape(Circle())
  27.             .shadow(radius: 3)
  28.             .padding(.top, 10)
  29.             .padding()
  30.             .padding()
  31.             Text("Orbit Radical Measurement")
  32.                 .font(.callout)
  33.                 .bold()
  34.             TextField("#", value: self.$orbit, formatter: formatter)
  35.             .onReceive(Just(self.orbit), perform: self.numericValidator)
  36.                 .textFieldStyle(RoundedBorderTextFieldStyle())
  37.                 .fixedSize(horizontal: true, vertical: /*@START_MENU_TOKEN@*/true/*@END_MENU_TOKEN@*/)
  38.         }.padding()
  39.     }
  40.  
  41.  
  42.     func convertCelsiusToFarenheit(_ celsius) -> Int { celsius * 9 / 5 + 32 } //<--@reddit user helper i put //your code here
  43.  
  44.  
  45.     func numericValidator(newValue: String) {
  46.         if newValue.range(of: "^\\d+$", options: .regularExpression) != nil {
  47.             self.orbit = newValue
  48.         } else if !self.orbit.isEmpty {
  49.             self.orbit = String(newValue.prefix(self.orbit.count - 1))
  50.         }
  51.     }
  52. }
  53. struct ContentView_Previews: PreviewProvider {
  54.     static var previews: some View {
  55.         Group {
  56.             ContentView().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
  57.         }
  58.        
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement