Post

Replies

Boosts

Views

Activity

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.
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’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)
Topic: Programming Languages SubTopic: Swift Tags:
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()     }
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
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.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Save When Program Exits
awal says If this is really when you want to save(), I suggest reading up on the lifecycle of an app and using appropriate scene delegate methods if that’s the flow your app used.  Of course, iOS doesn’t ever really tell you if your app has been force-terminated by the user. applicationWillTerminate seems like the appropriate method because it's called when the user terminates the app without switching it to the background.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Problem With Filter
Thanks Claude. I solved my filtering with the other scopes but the thing that lingers is I can't delete all the characters in the searchBar unless it's on scope 0 and once I delete characters I can't switch to any scope unless it's scope 0. OOPer says Can you show all the definitions of cPlayerArr, allTextArr, fetchAllPlayers(), fetchForwards(), fetchDefense(), fetchGoalies() and all the dataSource methods? They may not be implemented consistently. var cPlayerArr = [CurrentPlayers]()     //filters players based on scope var allTextArr = [CurrentPlayers]() func fetchForwards() {     do {       let request = CurrentPlayers.fetchRequest() as NSFetchRequestCurrentPlayers       let forwards = NSPredicate(format: "position CONTAINS 'RW' OR position CONTAINS 'LW' OR position CONTAINS 'C'")       request.predicate = forwards       self.allTextArr = try context.fetch(request)       DispatchQueue.main.async {         self.collections.reloadData()       }     }     catch {             }   }       func fetchDefense() {     do {       let request = CurrentPlayers.fetchRequest() as NSFetchRequestCurrentPlayers       let defense = NSPredicate(format: "position CONTAINS 'D'")       request.predicate = defense       self.allTextArr = try context.fetch(request)       DispatchQueue.main.async {         self.collections.reloadData()       }     }     catch {             }   }       func fetchGoalies() {     do {       let request = CurrentPlayers.fetchRequest() as NSFetchRequestCurrentPlayers       let goalies = NSPredicate(format: "position CONTAINS 'G'")       request.predicate = goalies       self.allTextArr = try context.fetch(request)       DispatchQueue.main.async {         self.collections.reloadData()       }     }     catch {             }   }      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) - UICollectionViewCell {         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "colcell", for: indexPath) as! PlayerColCell       if (searchBar.text != "" || searchBar.selectedScopeButtonIndex 0) {         item = allTextArr[indexPath.row]         cell.layer.borderColor = UIColor.black.cgColor         cell.layer.borderWidth = 0.5         cell.contentView.backgroundColor = UIColor(red: 102/256, green: 255/256, blue: 255/256, alpha: 0.6)         cell.update(with: item)         return cell       } else {         item = cPlayerArr[indexPath.row]         cell.layer.borderColor = UIColor.black.cgColor         cell.layer.borderWidth = 0.5         cell.contentView.backgroundColor = UIColor(red: 102/256, green: 255/256, blue: 255/256, alpha: 0.6)         cell.update(with: item)         return cell       }     }
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Problem With Filter
Claude31 says What happens when you delete all char in search bar ?  Can you delete all but the last ? One difference I see, is that in case 0 you clear the allTextArr array (what a bizarre name for [CurrentPlayers] array) and you reload them in other cases. Could you show the code of: fetchAllPlayers() I list my current issues with OOper's code and I called it allTextArr because I use text to filter but I changed it to filteredArr so it's more clear. Here is the code for fetchAllPlayers()    func fetchAllPlayers() {     parseJSON {       self.collections.reloadData()     }   } OOper says Thanks for showing your code. Checking your dataSource methods, your UICollectionView (collections) shows allTextArr when searchBar.selectedScopeButtonIndex 0. But in your searchBar(:textDidChange:), you update allTextArr from cPlayerArr. Generally: You need to re-fetch when selectedScopeButtonIndex is changed You need to re-filter when searchText is changed But your current searchBar(:textDidChange:) mixes up two different things -- re-fetch and re-filter. I would write them as follows: Okay I tried your solution but there are issues with selectedScope 0, When I filter for a specific player in selectedScope 0, I see multiple cells of the same player instead of one. When I delete all character it should clear and reload one of those fetch methods instead of giving multiple cells of the same player. After I delete all characters and when I try to start typing again in the searchBar I see no cells shown.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21