Post

Replies

Boosts

Views

Activity

Value of type 'some View' has no member 'onChange'
I'm new to SwiftUI and when I use the onChange modifier I get the following error. Value of type 'some View' has no member 'onChange' Here's the section of my code and if I remove line 9 - 26 my code will compile.            GeometryReader{reader in             VStack {               Image("race2")                 .resizable()                 .aspectRatio(contentMode: .fill)                .frame(width: UIScreen.main.bounds.width, height: reader.frame(in: .global).minY > 0 ? reader.frame(in: .global).minY + (UIScreen.main.bounds.height / 2.2) : UIScreen.main.bounds.height / 2.2)                 .offset(y: reader.frame(in: .global).minY)                 .onChange(of: reader.frame(in: .global).minY){value in                   let offset = value + ( UIScreen.main.bounds.height / 2.2)                   if offset < 80 {                     if offset > 0 {                       let opactity_value = (80 - opactity) / 80                       self.opacity = Double(opactity_value)                       return                     }                     self.opacity = 1                   }                   else {                     self.opacity = 0                   }               }             }           }
2
0
2.3k
Aug ’20
I'm struggling to figure out the best approach to get an alert to present with my current code
I'm wanting to present an alert message when a user doesn't have network connection. I have a function that will make an API call for data and also checking if there is network connectivity to avoid a crash. I'm sort of stuck on the best approach from here. func getRoutes(completion: @escaping ([Route]) -> ()) { //Post is data model &#9;&#9;&#9;&#9;let routeMonitor = NWPathMonitor() &#9;&#9;&#9;&#9;print("aMonitor is set") &#9;&#9;&#9;&#9;routeMonitor.pathUpdateHandler = { path in &#9;&#9;&#9;&#9;&#9;&#9;if path.status == .satisfied { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("We're connected! Let's grab route data") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;guard let url = URL(string: "<URL>") else { return &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("the JSON data didn't match") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;URLSession.shared.dataTask(with: url) { (data, _, _) in //_ means we're not going to use it now &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;let routes = try? JSONDecoder().decode([Route].self, from: data!) //decoding the data &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//allow us to interact with the app while API call is happening &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;DispatchQueue.main.async { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;if routes != nil&#9;{ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;completion(routes!) //&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print(routes!) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} else { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//TODO: Update error message &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("we're trying to get route data - errorstate \(self.dataError), alert state \(self.showingAlert)") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.resume() &#9;&#9;&#9;&#9;&#9;&#9;} else { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.dataError = true &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("No connection & data error set to \(self.dataError).") &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;print("Cell Data set to \(path.isExpensive)") &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;let routeQueue = DispatchQueue(label: "Route Monitor") &#9;&#9;&#9;&#9;routeMonitor.start(queue: routeQueue) &#9;&#9;} } Here's the call I make for onAppear to call the function      //MARK: API call to get race data       .onAppear{         Api().getRoutes{           (routes) in           self.routes = routes           print("Obserbed object: \(self.presentError.dataError)")           if self.presentError.dataError == true {             print("routeview error on getting data from api.getPosts \(self.presentError.dataError)")             return           }         }     } I thought I could put an if statement after (routes) in, but I never get to that far when there is no network connecvitiy.
1
0
470
Sep ’20
iOS14 Crash Fatal Unexpectedly found nil while unwrapping an Optional value
I'm getting into a crash only with iOS14 and Xcode 14 simulator. I don't see this issue when I was on iOS13 or Xcode 13 simulator. I'm using SafariServices to open a URL and the crash is happening at SafariView(url: URL(string: self.urlString)!) I felt fine forcing the unwrap because I know that self.urlString = self.dogood.link has a value from an Identifiable that I'm using. Am I looking at an iOS 14 bug possibly? struct SafariView: UIViewControllerRepresentable {   typealias UIViewControllerType = SFSafariViewController   var url: URL?   func makeUIViewController(context: UIViewControllerRepresentableContext<SafariView>) -> SFSafariViewController {     return SFSafariViewController(url: url!)   }   func updateUIViewController(_ safariViewController: SFSafariViewController, context: UIViewControllerRepresentableContext<SafariView>) {   } } struct DoGoodListView: View {   @State private var showSafari = false   @State private var urlString = ""   var dogood: DoGood   var body: some View {       VStack(spacing: 8.0) {         HStack {           Text(dogood.name)             .font(.title).bold()           Spacer()           Image(dogood.logo)           .resizable()           .aspectRatio(contentMode: .fit)           .cornerRadius(15)             .frame(width: 50, height: 50)         }         Text(dogood.info)         Button(action: {           self.urlString = self.dogood.link           self.showSafari = true           print(self.urlString)         }) {         Text("Visit")         .font(.system(size: 18, weight: .medium))         .frame(width: 250, height: 50)         .background(Color("card3"))         .clipShape(RoundedRectangle(cornerRadius: 30, style: .continuous))           .shadow(color: Color("card3").opacity(0.1), radius: 1, x: 0, y: 1)           .shadow(color: Color("card3").opacity(0.2), radius: 10, x: 0, y: 10)         .padding()         }         .sheet(isPresented: $showSafari) {           SafariView(url: URL(string: self.urlString)!)         }       }   } }
8
0
1.8k
Sep ’20
XPC connection interrupted crash to black screen
I'm using Xcode 11.7 and my app is targeted for 13.1 and when changing the State of a property in quick succession the app is crashing to a black screen and then returns to the lock screen. I'm not getting any crash report on the device and when I hook it up to Xcode I just get the following errors: 2020-09-15 06:42:28.586026-0400 [26842:7830878] XPC connection interrupted 2020-09-15 06:42:28.589083-0400 [26842:7831204] [ServicesDaemonManager] interruptionHandler is called. -[FontServicesDaemonManager connection]_block_invoke I'm not really sure how to troubleshoot this.
1
1
1.5k
Sep ’20
iOS14 shows content as blue
I noticed that with iOS14 navigationlinks and button content show all content as blue. The weird thing is if I pull down slightly on the sheet the colors revert. Here's a video of what I'm talking about. https://www.icloud.com/iclouddrive/02Ywhk6SiZn4NhUU45cZ2MNPw#iOS14 I tried using .renderingMode(.original) but that hasn't helped.
1
0
397
Sep ’20
Xcode12 Unnamed argument #2 must precede argument 'action'
Starting in Xcode 12 buttons are causing my code to not compile. At the basic level it's failing which was not failing in Xcode 11.*. import SwiftUI struct Foo1: View {   var body: some View {     VStack {       Button(action: print("How about now?")) {         Text("test")       }     }   } } struct Foo1_Previews: PreviewProvider {   static var previews: some View {     Foo1()   } }
2
0
2.1k
Sep ’20
How can I go about checking if Core Data contains X data?
So I call FetchRequest to get the data.      @FetchRequest(fetchRequest: FavoriteItem.getAllFavorites()) var isFavorite:FetchedResults<FavoriteItem> When I print out isFavorite I can see all the data in my coredata model, but I'm not sure how I can run a contain that data. This is what I thought would work if isFavorite.contains(foo.name) { print("it's already there nerd") } I get the error Cannot convert value of type 'String' to expected argument type 'FetchedResults<FavoriteItem>.Element' (aka 'FavoriteItem') Do I need to do a foreach and check each item?
4
0
1.3k
Sep ’20
Coredata crash on iOS 13 only
I have an app that is crashing only in iOS13. I don't see this issue on my iOS14 device or the simulator. Here's the error I get in the console and I included the breakpoint error. The crash is happening on line 14. Context in environment is not connected to a persistent store coordinator: <NSManagedObjectContext: 0x281050c40> Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1bf7c5678) struct BLAH: View { //&#9;&#9;Core data &#9;&#9;@Environment(\.managedObjectContext) var managedObjectContext &#9;&#9;@FetchRequest(fetchRequest: FavoriteItem.getAllFavorites()) var isFavorite:FetchedResults<FavoriteItem> &#9;&#9;var body: some View { &#9;&#9;... &#9;&#9;List { &#9;&#9;&#9; ... &#9;&#9;&#9;&#9;&#9;&#9;if hideFavorites == false { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach(isFavorite.filter({ <CRASH HERE> &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;searchText.isEmpty ? true : $0.name.lowercased().contains(searchText.lowercased()) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;})) {isFavorite in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;FavoriteView( &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;runclub: RunClubsv2.init(id: isFavorite.runclubid, name: isFavorite.name, location: isFavorite.location, date: isFavorite.date, category: isFavorite.category, dayofweek: isFavorite.dayofweek, link: isFavorite.link, hour: isFavorite.hour, minute: isFavorite.minute, favorite: false), &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;name: isFavorite.name, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;date: isFavorite.date, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;location: isFavorite.location, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;link: isFavorite.link, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;category: isFavorite.category, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;dayofweek: isFavorite.dayofweek, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;hour: isFavorite.hour, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;minute: isFavorite.minute, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;runclubid: isFavorite.runclubid &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}.onDelete { indexSet in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;let deleteItem = self.isFavorite[indexSet.first!] &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.managedObjectContext.delete(deleteItem) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;do { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;try self.managedObjectContext.save() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}catch { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print(error) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} }
0
0
787
Sep ’20
Xcode 12 MessageSendingError: Connection interrupted: send previewInstances message to agent
New SwiftUI files are no longer rendering preview in canvas. I'm getting the error MessageSendingError: Connection interrupted: send previewInstances message to agent.&#9; Existing views still render so far, but the default hello world isn't rendering. I've restarted Xcode, my mac, clean and rebuilt the project and no change. I've tried add .environment(\.colorScheme, .dark) to the preview and that made no difference as well. What am I missing?
1
0
1.3k
Sep ’20
JSON Decoded data not getting returned to be used.
I created a class and a function to make an API call and return some data. I get the data back in the console, but I'm not able to use the data and I think it's because I'm not completing the data correctly. The data being returned is surrounded by { } instead of [ ]. The function looks like this: func getBusinessInfo(completion: @escaping ([Welcome]) -> ()) { ...        let task = URLSession.shared.dataTask(with: request) { (data, response, error) in ...        if let yelpbusinessinfo = data {         let decoder = JSONDecoder()         let yelpbusinessinfo = try? decoder.decode(Welcome.self, from: yelpbusinessinfo)         print(yelpbusinessinfo?.reviews[1].text)         completion(yelpbusinessinfo!)       } At completion(yelpbusinessinfo!) I get the following error in the compiler and I'm assuming it has to do with how the data is being returned. Cannot convert value of type 'Welcome' to expected argument type '[Welcome]' Any help on what the proper format should be?
12
0
2.4k
Oct ’20
Plotting map annotations from a JSON response
I'm trying to plot out map annotations from a JSON Response using MapKit. I've figured out some basic ways to plot out map points, but I"m not sure entirely what MapKit is expecting for map points. In my JSON response my struct is // MARK: - Business struct Business: Codable, Identifiable {   let id, alias, name: String   let coordinates: Center } struct Center: Codable {   let latitude, longitude: Double } Then my code looks like this, but I think I'm using CLLocationCoordinate2DMake incorrectly.    @State var yelpbusinessdataMap: WelcomeBusiness? = nil    var body: some View {     Map(coordinateRegion: $region,       interactionModes: MapInteractionModes.all,       showsUserLocation: true,       userTrackingMode: $userTrackingMode,       annotationItems: yelpbusinessdataMap?.businesses ?? []     )     { places in       var new2DCoord = CLLocationCoordinate2DMake(places.coordinates.latitude, places.coordinates.longitude)       MapAnnotation(         coordinate:           new2DCoord,         anchorPoint: CGPoint(x: 0.5, y: 0.5)       ){         Circle()           .stroke(Color.green)           .frame(width: 44, height: 44)       }     } I tried using coordinate: places.coordinates,, but I get the following compiler error Cannot convert value of type 'Center' to expected argument type 'CLLocationCoordinate2D'
2
0
1.1k
Oct ’20
iOS 14.1 - xCode 12.1 onTapGesture inconsistent
I found in the latest update of iOS and xCode that onTapGesture isn't consistently registering onTap. Here's a stripped down version of the code I'm using that reproduces this issue. In this case onTap for safari is not working. I don't reproduce this with iOS13 or if I'm using onLongPress Has anyone else experienced this in the latest update?   @State var runclubs: [RunClubsv2] = []   //Search filter   @State var showSearch = false   @State private var searchText: String = ""   @Binding var showRuns: Bool   @State var tap = false   @State var showActionSheet = false   //States for weeks   @State var hideSunday = false   @State var hideFavorites = false   //View   @State var clubInfo = false   @State private var urlString = ""   @State private var showSafari = false   var body: some View {     ZStack {       VStack {         List {           //TODO: Add section filtering.           HStack {             Text("Run Clubs")               .font(.title).bold()             Spacer()           }           Section(header:                 HStack {                   Text("Sunday")                     .font(.subheadline)                     .padding(.vertical, 5)                   Image(systemName: hideSunday ? "chevron.up": "chevron.down")                     .foregroundColor(Color("carolinablue"))                     .rotation3DEffect(Angle(degrees: hideSunday ? 180 : 0), axis: (x: 0, y: 90, z: 0))                 }                 .animation(.easeInOut(duration: 0.2))                 .onTapGesture {                   self.hideSunday.toggle()                 })           {             if hideSunday == false {               //display data               ForEach(runclubs.filter({                 searchText.isEmpty ? true : $0.name.lowercased().contains(searchText.lowercased())               })) { item in                 if item.category == "Sunday" {                   ZStack {                     HStack {                       //MARK: Background color                       Color(clubInfo ? "carolinablue" : "card3")                         .frame(width: 30, height: 575)                         .cornerRadius(3)                         .frame(width: 6, height: 75, alignment: .leading)                         .background(Color( colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)).opacity(0.08))                         .cornerRadius(3)                         .padding()                         .frame(width: 3, height: 55)                         .background(Color.black.opacity(0.1))                         .cornerRadius(12)                         .scaleEffect(clubInfo ? 0.8 : 1)                         .animation(.interpolatingSpring(mass: 1.0,stiffness: 100, damping: 6.0))                       //MARK: Runclub top section                       VStack(alignment: .leading, spacing: 8.0) {                         HStack {                           ZStack(alignment: .leading) {                             Text(item.name)                               .font(.headline)                               .animation(.easeOut(duration: 0.4))                               .rotation3DEffect(Angle(degrees: clubInfo ? 90 : 0), axis: (x: 90, y: 0, z: 0))                             Text(item.location)                               .font(.headline)                               .rotation3DEffect(Angle(degrees: clubInfo ? 0 : 90), axis: (x: 90, y: 0, z: 0))                               .animation(.easeOut(duration: 0.4))                           }                           Spacer()                           Image(systemName: clubInfo ? "chevron.up": "chevron.down")                             .font(.system(size: 20, weight: .medium))                             .foregroundColor(Color("carolinablue"))                             .rotation3DEffect(Angle(degrees: clubInfo ? 180 : 0), axis: (x: 0, y: 90, z: 0))                             .shadow(color: Color("carolinablue"), radius: 12, x: 0, y: 0)                             .onTapGesture{                               self.clubInfo.toggle()                             }                         }                         //MARK: Runclub bottom section                         HStack {                           ZStack(alignment: .leading) {                             HStack {                               Image(systemName: "safari")                               Text("Link for more Info")                                 .font(.subheadline)                                 .onTapGesture {                                   self.showSafari = true                                   self.urlString = item.link                                   print("urlString \(self.urlString)")                                 }                               Spacer()                             }                             .animation(.easeOut(duration: 0.4))                             .rotation3DEffect(Angle(degrees: clubInfo ? 0 : 90), axis: (x: 90, y: 0, z: 0)) //                            .allowsHitTesting(clubInfo ? true : false)                             HStack {                               Text(item.location)                                 .font(.subheadline)                                 .rotation3DEffect(Angle(degrees: clubInfo ? 90 : 0), axis: (x: 90, y: 0, z: 0))                               Spacer()                               //                             }                           }                           .animation(.easeOut(duration: 0.4))                         }                       }                       //testing long press here to prevent scrolling issues.                       .onLongPressGesture {                         self.showSafari = true                         self.clubInfo = false                         self.urlString = item.link                       }                     }                   }                   .sheet(isPresented: $showSafari) {                     SafariView(urlString: self.$urlString)                   }                   .padding(.horizontal, 15)                   .frame(height: 90)                   .background(Color(clubInfo ? "background3" : "background2"))                   .animation(.easeInOut(duration: 0.3))                   .clipShape(RoundedRectangle(cornerRadius: 20, style: .continuous))                   .shadow(color: Color("background2").opacity(0.8), radius: 10, x: 0, y: 10)                   .padding(.vertical, 13)                 }               }             }           }         }       }       .padding(.top, 15)       .onTapGesture {         self.hideKeyboard()       }       .navigationBarItems(trailing: EditButton())     }     //MARK: Call for run club data     .onAppear{       print("onappear making API call for data")       Api().getRunClub(url: "https://api.npoint.io/a5a1f2a53b3856ceed34") { (runclubs) in         self.runclubs = runclubs         print("We got the run run clubs")       }     }     .padding(.top, 65)   } }
0
0
601
Oct ’20
Is it possible to delete an item from Coredata using onTapGesture?
I know about .onDelete modifier, but say I want to remove an item from Coredata using onTapGesture is that possible?  .onDelete { indexSet in           let deleteItem = self.isFavorite[indexSet.first!]           self.managedObjectContext.delete(deleteItem)           do {             try self.managedObjectContext.save()           }catch {             print(error)           }         } I tried doing          .onTapGesture { indexSet in           let deleteItem = self.isFavorite[indexSet.first!]           self.managedObjectContext.delete(deleteItem)           do {             try self.managedObjectContext.save()           }catch {             print(error)           }         } But that didn't go well.
4
0
1.9k
Nov ’20