Post

Replies

Boosts

Views

Activity

How do I show the whole month name and not 3 letters?
Hello, How do I show the whole month name and not just 3 letters? import SwiftUI struct ContentView: View {     @State var dateString = ""     var body: some View {         VStack {             Image(systemName: "globe")                 .imageScale(.large)                 .foregroundColor(.accentColor)             Text(dateString)         }         .onAppear{             dateString = Date.now.formatted(.dateTime.month().day().year())         }     } }
1
0
614
Aug ’22
SwiftUI and MapKit error, thread 1
Greetings, in the @main file I keep getting this error, "Thread 1: "-[MTLSimHeap protectionOptions]: unrecognized selector sent to instance 0x600001864d20"" I have no idea what's causing it and how to solve it. Here is the code: import SwiftUI import MapKit struct ContentView: View { @StateObject private var viewModel = ContentViewModel()    var body: some View { ZStack {        Map(coordinateRegion: $viewModel.region, showsUserLocation: true) .accentColor(.blue) .onAppear{                 viewModel.checkIfLocationServicesEnabled()                                      }                      }     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } } final class ContentViewModel: NSObject, ObservableObject, CLLocationManagerDelegate{          var locationManager: CLLocationManager?          @Published var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 37.331516, longitude: -121.891054), span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))          func checkIfLocationServicesEnabled() {         if CLLocationManager.locationServicesEnabled() {             locationManager = CLLocationManager()             locationManager!.delegate = self                      } else {             print("show alert: location is off.")         }     }   private func checkLocationAuthorization() {                guard let locationManager = locationManager else { return }                  switch locationManager.authorizationStatus {                          case .notDetermined:             locationManager.requestWhenInUseAuthorization()                          case .restricted:             print("Your Location is restricted likely due to parental controls.")             case .denied:             print("You denied this app location permission, go to the settings to change it.")             case .authorizedAlways, .authorizedWhenInUse:             region = MKCoordinateRegion(center: locationManager.location!.coordinate, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))             @unknown default:             break         }     }          func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {         checkLocationAuthorization()     } } The @main file: import SwiftUI @main struct MyApp: App {               var body: some Scene {         WindowGroup {             ContentView()         }     } }
1
0
583
Aug ’22
ForEach and variable
Greetings, can’t increase number of times ForEach is repeated, any solution? import SwiftUI struct ContentView: View {          @State var numberOfTimes: Int = 0          var body: some View {         VStack {             ForEach(1..<numberOfTimes, id: \.self) { i in                  Text("i \(i)")             }              Text("Add one")                 .onTapGesture {                     numberOfTimes = numberOfTimes + 1                 }         }     } }
1
1
385
Aug ’22
Jamie
I keep getting this error,” Cannot convert value of type ‘Currentlydoing.Type’ to expected argument type ‘Currrentlydoing”. When I remove the,”done: Currentlydoing” it gives an error saying,”Missing argument for parameter ‘done’ in call insert done: ,#Currenlydoing# “ but when I insert it it gives the original error. What’s the solution? import SwiftUI struct ContentView: View {    var done: Currentlydoing var body: some View {         VStack { Text(done.sleep ? "Hello":"HI")             }     } } struct MainView: View {     var body: some View {         ContentView()     } } struct Currentlydoing: Identifiable, Codable {     var id: String     var text : String     var work: Bool     var sleep: Bool }
1
0
446
Aug ’22