Post

Replies

Boosts

Views

Created

An instance of NSFetchedResultsController requires a non-nil fetchRequest and managedObjectContext
I am trying, for learning sake, to make a hybrid database app that will allow the user to store data locally and will allow the user to connect to an external database. I have a controller (MainController.swift) file that houses the code that will interact with the Suggest Table that I have in my Main View Controller. Here is the code (sorry, its long): import UIKit import CoreData class MainController: UIViewController, NSFetchedResultsControllerDelegate {     // MARK: UI Components     // Suggestions Table     @IBOutlet weak var dataTableView: UITableView!     @IBOutlet weak var suggestLabel: UILabel!          // MARK: Variables     private var suggests = [Suggest]() {         didSet {             updateMainView()         }     }          private let persistContainer = NSPersistentContainer(name: "Suggest")          fileprivate lazy var fetchedResults:NSFetchedResultsController<Suggest> = {         let fetchRequest: NSFetchRequest<Suggest> = Suggest.fetchRequest()         fetchRequest.sortDescriptors = [NSSortDescriptor(key: "createdAt", ascending: true)]                  let fetchedResults = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.persistContainer.viewContext, sectionNameKeyPath: nil, cacheName: nil)                  fetchedResults.delegate = self                  return fetchedResults     }()     override func viewDidLoad() {         super.viewDidLoad()         // Do any additional setup after loading the view.         dataTableView.dataSource = self         dataTableView.delegate = self                  setupMainView()                  // Load persistent container modules         persistContainer.loadPersistentStores { (persistenStoreDescription, error) in             if let error = error {                 print("[-] Unable to load persistent container -> \(error) : \(error.localizedDescription)")             } else {                 self.setupMainView()                                  do {                     try self.fetchedResults.performFetch()                 } catch {                     let fetchError = error as NSError                     print("[-] Unable to perform fetch request -> \(fetchError) : \(fetchError.localizedDescription)")                 }                                  self.updateMainView()             }         }     }          // MARK: Add-On functions and methods     private func updateMainView() {         var hashSuggest = false                  if let suggests = fetchedResults.fetchedObjects {             hashSuggest = suggests.count > 0         }                  dataTableView.isHidden = !hashSuggest                  if hashSuggest { suggestLabel.text = "Suggested Databases" }     }          private func setupMainView() -> Void {         suggestLabel.text = defaultNoSuggestsString()                  updateMainView()     }          private func defaultNoSuggestsString() -> String { return "No suggested databases...Error" }          @nonobjc public class func performFetch() -> NSFetchRequest<Suggest> {         return NSFetchRequest<Suggest>(entityName: "Suggest");     } } // MARK: Extensions extension MainController: UITableViewDelegate, UITableViewDataSource {     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {         guard let suggests = fetchedResults.fetchedObjects else { return 0 }         return suggests.count     }          func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {         guard let cell = tableView.dequeueReusableCell(withIdentifier: "suggestCell", for: indexPath) as? SuggestedCellStructure else {             fatalError("Unexpected Index Path")         }                  // Fetch the data modules         let module = fetchedResults.object(at: indexPath)                  // Image config         let image = UIImage(systemName: module.image_string!)         let mainImage = UIImageView(image: image)                  // Configure the cell         cell.suggestTitle.text = module.title_string         cell.suggestDesc.text = module.desc_string         cell.welcomingImage = mainImage                  return cell     } } I have the Core Data structure here as well (Image 01) with the Name defined as the Class. When every I run the app to test, I get this error message: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An instance of NSFetchedResultsController requires a non-nil fetchRequest and managedObjectContext' - terminating with uncaught exception of type NSException The Name is defined in the Core Data Structure file and the Codegen is defined as "Class Definition" so...im not seeing what is wrong. Here is also the TableViewCell structure profile code: import Foundation import UIKit class SuggestedCellStructure: UITableViewCell {          @IBOutlet weak var welcomingImage: UIImageView!     @IBOutlet weak var suggestTitle: UILabel!     @IBOutlet weak var suggestDesc: UITextView!     @IBOutlet weak var initSuggest: UIButton!      }
1
0
1.1k
Mar ’22
Importing a custom programmed swift package
I have made a custom swift package that contains the encoding and decoding functions for my app String Conversion Tool. It is uploaded to GitHub: (https://github.com/Casual3306/ConverterExtra). I do a request for the package (in my apps main project) and the package imports just fine, it is present in the Frameworks, Libraries, and Embedded Content and it is present in Package Dependencies, I have also run: "Reset Package Caches" and "Resolve Package Versions". The package also imports into the designated module as a "module" but when I try to access any of that "modules" files like > ConverterExtras > Encoders it is giving me an error saying that "This class may not be available in this context". All of the files are in the module package but Xcode isn't finding them for some reason: Xcode version: 13 System: MacOS (Big Sur 11.6)
2
0
3.4k
Oct ’21
Copy&Paste with select disabled not showing for UITextField
I have a UITextField outlet declared in my primary view controller that is attached to the "encoder" tab. The "ViewController.swift" is linked to the ViewController. For some reason when a double tap (and or hold) the UITextField, the copy, paste, select/select all options are not showing. They are supposed to show even though the text field module is empty. I tried to implement this: override var canBecomeFirstResponder: Bool {         return true } override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { &#9; return (action ==&#9;&#9;&#9;&#9;&#9;&#9;&#9; #selector(UIResponderStandardEditActions.paste(_:))) } It gives me the paste option but the thread crashes with this message: Thread 1: "-[String_Conversion_Tool.ViewController paste:]: unrecognized selector sent to instance 0x104e09860" How can I enable the copy, paste, select/select all options for the UITextField like it was before? or how can I enable them programatically?
6
0
6.1k
Oct ’20
class is not key value coding-compliant for the key mainScrollView
I am working on a new project, String Converter which will be run on a device supporting iOS 13.0 and up. My problem is in the Tab Layout, specifically the encoder tab I have a UIScrollView (and UIView inside that module) set up and linked as "mainScrollView" in the custom class "FirstViewController.swift". The outlet for mainScrollView is in the class FirstViewController which is set as the custom class for the Encoder Scene. The mainScrollView (UIScrollView) outlet is set as linked to the UIScrollView module object in that specific scene (Encoder Scene). The link is displayed as set in the "Connection Inspector" under "Outlets" and as said previously that UIScrollView module is in the FirstViewController class. Despite everything (seemingly) being there, I am still getting this error message (which is displayed when the app terminates and takes me to the AppDelegate.swift file): Thread 1: Exception: "[<UIViewController 0x7f85ea557bb0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key mainScrollView.
11
0
5.3k
Sep ’20