I am new in iOS and core data. Can anyone give me a example to fetch data from core data through NSFetchedResultsController and display in UITableView
Thanks in advance :)
This question is almost too general for this platform. You are expected to at least try something yourself.
One obvious thing to do is to look at the documentation. You should have found out that the core data template in Xcode has a functioning table view based on NSFetchedResultsController.
Create new project
Choose master-detail
Check Core Data
Examine the master view controller
Related
Although there seems to be plenty of information on UISearchControllers, many of the approaches I have found have been deprecated in iOS 8. Most tutorials I have found use UISearchDisplayController, which is deprecated, and even the documentation on UISearchController uses convenience methods that have also been deprecated. I'm looking for someone who knows how to successfully search items in a UITableView that is backed by core data in iOS 8.
Currently I have a table view that that fetches and displays points of interest saved from a map view. Pretty standard boilerplate stuff - just persisting and fetching entities. The challenging part of this is adding a UISearchController, which recently replaced the UISearchDisplayController,to the table view that is backed by core data (the tableview displays any point of interest entity persisted to the data store). Using core data instead of a standard array is where the complication begins, and there isn't sufficient documentation using this particular approach. Open to any and all suggestions.
To kick things off, lets consider that I have stored my fetched items from core data in a mutable array. How would we go about using that to filter our table view?
self.searchResults = [NSMutableArray arrayWithCapacity:[[self.fetchController fetchedObjects] count]];
You should be using a NSFetchedResultsController to display your Core Data backed data in a table view. Please read up on that first. Boilerplate available via Xcode templates.
For searching, you can e.g. just invalidate the fetched results controller and let it recreate it lazily. When creating it, add a predicate for the search term.
The UISearchController will simply help you keep track of the usual search event, i.e. search text change, scope changed, cancel etc.
New to iOS development..
Basically what i'm trying to do is hard code data into my app using core data. Two different types will be stored, both strings: quotes and authors (There will be around 20 of each in the app). I have a button on my Storyboard as an IBaction that when clicked will populate a label with a new quote and author. My struggle right now is 1) finding out how to create this data and 2) how to fetch this data.
Every resource i'm finding online goes through tutorials on how to store data that a user typed in and then fetch it from a button. I'm trying to figure out how to store data without user input and then fetch it. Any help is appreciated. Sorry for asking what I am sure is a pretty simple question.
Unfortunately, though this would seem like a simple task, to my knowledge there is know "built-in" way to prepopulate CoreData. You can build up a core database and then copy it into an app, or possibly use a third party solution, though. Searching for "prepopulate coredata" here and on google should give you a start.
Here's a couple threads that might help:
Any way to pre populate core data?
iOS CoreData - prepopulate db with existing indexes
I'm currently writing my first iOS app and I'm trying to implement Core Data. Users create food recipes and I want them saved to persistent storage.
Currently, without Core Data, I'm putting the recipes into an array from a singleton.
When I implement Core Data can I do away with this and fetch straight from the data model every time I need to update my UITableView? In the viewDidLoad method, create an array from the current data in Core Data every time a user navigates to it?
Yes you can.
You should look at the class NSFetchedResultsController it is designed to do this.
There is a great Ray Wenderlich tutorial which covers everything including things like automatically updating the table when the core data model changes etc...
I have been through a couple of these answers here, but I don't think I get it right..
I have several NSArray made of JSON requests. I want to store everything in the app instead of requesting the data all the time, and I understand I should use Core Data for this.
The problem is, I don't know how to initialize this.. I have tried to read up, but I have realized it will take a long time to understand this by just reading the class reference etc.
I have added an .xcdatamodel and created an entity with attributes identical to the data in one of the json object. How can I access the file for extracting and inserting information? I plan on parsing my whole json object into this file, but how can I instantiate the entity? Which delegates and where?
All tutorials I have watched had an option when they created the project, like "Use Core Data" or something, which when checked created lots of code automatically. I don't have that..
You might wanna go through some SO links: here. Also, I once remember going through this guide for adding Core Data to my project. It might help you to go through this link for saving JSON to Core Data directly. I recommended this link here in SO a couple of times. Trust me, all this pain you are enduring setting up Core Data is well worth it when you see things starting to work!
You need to add the core data stack. You can create a new, core data project, and get the core data elements added to the app delegate specifically for core data. You will have 3 properties, and one method. Just copy/paste the declaration and implementation of these elements to your app delegate. Make sure the managedObjectModel method and the persistentStoreCoordinator method are using your actual model name.
To work with core data, you need to read the core data documentation:
http://developer.apple.com/library/mac/#documentation/cocoa/Conceptual/CoreData/cdProgrammingGuide.html
You will have to create entities to represent your data, the properties for the entities, and so fort. Get started with your project, read the documentation, and get started. You will have more questions which you will either ask or find here, but at least you got enough to get started.
Im new to objective-c and I've been reading up on singleton classes. I want to implement it into my logic but im not sure if its correct/possible/doable to do so, any advise would be appreciated.
At the moment i'm loading data from an xml feed, but i want to have control what data should be displayed based on which button is clicked. For example, buttonA would display IT news and buttonB would display celebrity news.
My thinking is to load the xml data into sqlite on application start in the background and display my buttons view at the same time using the singleton class. If the user pushes the button it will query the required table and display the content into a tableView.
Is this viable? If not, could you please advise whats the best way to go about this?
Thank you.
First of all you should reconsider organization of your data model. You've named sqlite on one hand and a global array on the other.
I would point you to Core Data to store your parsed data in a convenient way. Finally all you need is to query the Core Data db and fetch what you need. This would be more memory efficient than storing your data in a global array.
Have a look at Apple's Core Data tutorial or at this nice turorial: "superdb-core-data-app-with-sections"
To share a managed object context you can use a singleton. Have a look at this blog post, it provides a solution without a singleton by passing references of the managed object context down the relevant objects. It is created in the app delegate.