Post

Replies

Boosts

Views

Activity

Reply to Remove Empty Names
I'm wondering how I can modify this function because it prints 0 for both arrays even though I call an API beforehand.    func filterArr() {     cPlayerArrB = cPlayerArr.filter(){       $0.yahooName != ""     }     print(cPlayerArr.count)     print(cPlayerArrB.count)   }
Mar ’21
Reply to Core Data Make Decodable
This is the whole class and related methods. @main class AppDelegate: UIResponder, UIApplicationDelegate {     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) - Bool {     // Override point for customization after application launch.     return true   }   // MARK: UISceneSession Lifecycle   func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) - UISceneConfiguration {     return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)   }   func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: SetUISceneSession) {   }           // MARK: CoreData   lazy var persistentContainer: NSPersistentContainer = {     */     let container = NSPersistentContainer(name: "playerModel")     container.loadPersistentStores(completionHandler: { (storeDescription, error) in       if let error = error as NSError? {         fatalError("Unresolved error \(error), \(error.userInfo)")       }     })     return container   }()       func saveContext () {     let context = persistentContainer.viewContext     if context.hasChanges {       do {         try context.save()       } catch {         let nserror = error as NSError         fatalError("Unresolved error \(nserror), \(nserror.userInfo)")       }     }   } }
Mar ’21
Reply to Core Data Make Decodable
I can show you the method but I will have to remove the API key. func parseJSON(completed: @escaping () - ()) {     let url = URL(string: "WebsiteLink")     let decoder = JSONDecoder()     decoder.userInfo[.managedObjectContext] = persistentContainer.viewContext() //persistentContainer not in scope     URLSession.shared.dataTask(with: url!) { (data, response, error) in               if error == nil {         do {           self.cPlayerArr = try JSONDecoder().decode([CurrentPlayers].self, from: data!)           let json = try JSONSerialization.jsonObject(with: data!, options: [])           print(json)                       DispatchQueue.main.async {             completed()           }         } catch {           print("JSON Error: ", error)         }       }             }.resume()   }
Mar ’21
Reply to Core Data Make Decodable
I'm having trouble adding this line to my request       decoder.userInfo[.managedObjectContext] = persistentContainer.viewContext() it tells me it doesn't find persistentContainer in scope even though I had persistent container declared in my appDelegate file.    // MARK: CoreData   lazy var persistentContainer: NSPersistentContainer = {     let container = NSPersistentContainer(name: "playerModel")     container.loadPersistentStores(completionHandler: { (storeDescription, error) in       if let error = error as NSError? {         fatalError("Unresolved error \(error), \(error.userInfo)")       }     })     return container   }()
Mar ’21
Reply to Protocol Not Working
I can transfer the data using the prepare method like so in my hockeyDetailVC override func prepare(for segue: UIStoryboardSegue, sender: Any?) {     if segue.identifier == "r" {     let destinationController = segue.destination as! FavouritesVC     destinationController.currentFav = item!   }   } but I am still curious about why my protocol is not transferring the data I want to send. I copied    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {    if segue.identifier == "r" {      print("segue identifier", segue.identifier)      let hockeyDetailVC: HockeyDetailVC = segue.destination as! HockeyDetailVC      hockeyDetailVC.delegate = self      print("destination HockeyDetailVC is", hockeyDetailVC)    }   } It does not print the segue.identifier it prints the delegate is nil and then it just crashes again. It does not matter what I change my segue.identifier too.
Feb ’21
Reply to Protocol Not Working
This is how I define the function   override func prepare(for segue: UIStoryboardSegue, sender: Any?) {   if segue.identifier == "r" {     print("segue identifier", segue.identifier)     let hockeyDetailVC: HockeyDetailVC = segue.destination as! HockeyDetailVC     hockeyDetailVC.delegate = self     print("destination HockeyDetailVC is", hockeyDetailVC)   }  } I don't use an IB but I have an identifier I named r in the storyboard.
Jan ’21