Post

Replies

Boosts

Views

Activity

Reply to Save When Program Exits
szymczyk says Make sure the saveContext function is called by setting a breakpoint on that line of code. Does it get called in applicationWillTerminate? I made a mistake in my first reply. For an iOS app the function where you should save the context is applicationDidEnterBackground. That's the function that will be called when someone quits the app. The applicationWillTerminate function does not get called until the app is purged from memory completely, which requires the user to launch several apps after quitting your app. I tried your solution but it still does not save the favourites when it terminates and the function does not get called at all.  func applicationDidEnterBackground(_ application: UIApplication) {       PersistenceService.saveContext()   } szymczyk says Can you explain what you mean by "make the object persistent"? Saving the context is how you save data in Core Data. I'm thinking that I have to initialize my item object with NSManagedContext so that it can be saved locally to the device.
Apr ’21
Reply to Save When Program Exits
Okay I have the function you are talking about in AppDelegate but it does not save my data when I terminate the app. Are you sure I don't have to make the object persistent?    func applicationWillTerminate(_ application: UIApplication) {       /* Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground*/       PersistenceService.saveContext()     }
Apr ’21
Reply to Notification Center Help
@Claude You say: Please, when you answer and there are several posts, please remind who you are replying to. Your solution works and it is currentFav but I want to make a minor modification this piece of code pushes my HdVC to FavVC but I'm wondering if there's a way I can have my data be transferred without navigating to FaVC (just stay at HdVC but transfer data to FaVC)? self.present(passDataVC, animated: true, completion: nil)
Apr ’21
Reply to Pass Data Forward Tips
The issue with push is because I want to stay on the same initial screen. Like with facebook when you get a friend request and add a friend you don't go to your all friends section when you click add friend, you stay on the same screen as the friend request. That's what I want to do with adding to my favVC.
Mar ’21
Reply to Modify API to remove empty names.
This is an example of a json object, I can print it but it just does not seem to parse anymore. I had to remove some url fields.  {     BirthCity = Pittsburgh;     BirthDate = "1993-07-11T00:00:00";     BirthState = PA;     Catches = "null";     DepthChartOrder = 5;     DepthChartPosition = C;     DraftKingsName = "Vincent Trocheck";     DraftKingsPlayerID = 607956;     FanDuelName = "Vincent Trocheck";     FanDuelPlayerID = 15283;     FantasyAlarmPlayerID = 400963;     FantasyDraftName = "Vincent Trocheck";     FantasyDraftPlayerID = 1818113;     FirstName = Vincent;     GlobalTeamID = 30000009;     Height = 70;     InjuryBodyPart = Scrambled;     InjuryNotes = Scrambled;     InjuryStartDate = "2021-03-18T00:00:00";     InjuryStatus = Scrambled;     Jersey = 16;     LastName = Trocheck;     PlayerID = 30000226;     Position = C;     RotoWirePlayerID = 3784;     RotoworldPlayerID = 3768;     Shoots = R;     SportRadarPlayerID = "16bf9f68-95f9-4789-a811-80fe6838e632";     SportsDirectPlayerID = 4433;     StatsPlayerID = 607956;     Status = Active;     Team = CAR;     TeamID = 9;     UsaTodayPlayerID = 8256334;     Weight = 183;     XmlTeamPlayerID = 19046;     YahooName = "Vincent Trocheck";     YahooPlayerID = 5431;   }
Mar ’21
Reply to Modify API to remove empty names.
Okay just one more thing, I'm trying to handle the nil values in my jerseyNumber but when I do my guard statement it somehow blocks the json from being parsed. Is there another way to deal with nil values from jerseyNumber? struct ApiCurrentPlayers: Decodable {   var PhotoUrl: String?   var FirstName: String?   var LastName: String?   var Position: String?   var Team: String?   var YahooName: String?   var Status: String?   var JerseyNumber: Int64? } extension CurrentPlayers {   convenience init?(context: NSManagedObjectContext, apiCurrentPlayers: ApiCurrentPlayers) {     guard let yahooName = apiCurrentPlayers.YahooName else {       return nil     } guard apiCurrentPlayers.JerseyNumber != nil else {       return nil     }     self.init(context: context)     self.photoUrl = apiCurrentPlayers.PhotoUrl ?? ""     self.firstName = apiCurrentPlayers.FirstName ?? ""     self.lastName = apiCurrentPlayers.LastName ?? ""     self.position = apiCurrentPlayers.Position ?? ""     self.team = apiCurrentPlayers.Team ?? ""     self.yahooName = yahooName     self.status = apiCurrentPlayers.Status ?? ""     self.jerseyNumber = apiCurrentPlayers.JerseyNumber!   } }
Mar ’21