Does iOS contain database? [closed] - ios

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am wondering if iOS has any build-in database, and if so - maybe you can direct me to some tutorials and/or API-description online ( similare to the JavaDocs ).
I am new to iOS and Objective-C programming. I have experience with Java and Android-development, and I am currently developing an Android-application for containing what CD's I have in my possession / collection - and want to re-produce it to iOS.
I have gotten stuck at the point at where I'm not sure how to save the information for the iOS-application. In Android you have an built-in database that you can use, and I stumbled upon an input ( here on StackOverflow ) a while back that someone wrote something about an SQLite-database and I would like to create an database first-time the application is run.
The alternative would be to save an file ( XML or JSON ) containing the information. But as the application is meant to handle large sums of information I want to use an database of some sort.
Thanks for all the possible help and directions to where I can find more information.

iOS has Core Data that works great in most of the cases. If you are used to Android's SQLite you can also use SQLite in iOS. Although, in general, people use Core Data.
XCode provides you a set of tools to work with Core Data. You can create a model inside XCode and see the relationship between Entities. Core data is not a relational database. It can be persisted in a relational database (SQLite) but the concept that supports Core Data is different. Core data is "an object graph manager with lifecycle" and you shouldn't fight against that concept. Try to understand the differences before dive into Core Data.
Dylan touched an important part. You also have wrappers and tools to help you with SQLite. One of them is FMDB.
For CoreData you also have a framework that can help you called MagicalRecord.

Yes, iOS come with built in core data feature. Here is the tutorial you can start with.

Related

Combining Data Sources/Persistence in SwiftUI Options/Best Practices? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I am newish to Swift/SwiftUI and have been reading a ton of resources. Using what I am learning along with another example app similar to what I am trying to create, I am making an app that downloads a JSON file from an external API service. That JSON data contains the main part of my code (items from a video game), and my app displays that data in various views. My question though is this: I want a user to be able to track a few things about each object, such as whether they have collected it. I have spent 2-3 weeks researching and trying various options of how to do this, but I am wondering what the most efficient/most popular way of doing something like this is in real-world apps?
Here are some things I have been considering:
Download the API JSON initially and then create both it and my collection data as one object. From there, I would persist that data either be encoding back to a JSON file to be stored in the app's documents directory or in Core Data (or even Realm). The views would actually pull from my own personal data. My first concern with this method is that the API JSON may have changes at some point and I would like the app to always have the most up-to-date version of that info (and I don't know how to compare for updated info yet). My second concern is why keep all of that extra info locally in my app when someone else is already hosting it (or should I do that anyway so the app can be used offline)? If that is the case, is there a tutorial or something around that shows how to manage downloaded JSON data without completely overwriting current data?
Download the API JSON as I currently am (every time a view needs it), and store the collection info as its own data. This is the method I think makes more sense, but my question is how do I combine it with the API JSON? Is it easiest to use JSON or Core Data to combine these files? Do I use the Combine framework? Are there other frameworks/methods that would be better suited for that?
To sum up:
My app downloads JSON files from an API containing items from a game that can be collected. I want the user to be able to track whether they have collected said items from that game. I don't know the best way to do this or what framework/classes I should be researching to do this. Any help would be greatly appreciated.
Warning: Most tutorials for CoreData and SwiftUI, FYI, both ignore MVVM (e.g., using #FetchRequest so your view directly reads your model) and the benefits of abstracting your persistence choice with a DataManager object and protocol. Doing the latter lets you choose CoreData now and switch to Google Firebase later (i.e., launching a collaborative Android version), without changing any View code or really any ViewModel code. You can follow the same principles with JSON decoding as just a different DataManger for initializing data for your ViewModel to apportion to views. Ok, done with soap box.
If your dataset is really big and you plan to query it sideways, CoreData may be nice. Or just a skill to learn. It's not that bad.
But if the use case is something simple like
Character 1
-- isStarredAsAwesome
-- copiesCollected
-- maxLevelofCopyCollected
-- dateCollected
Then just save JSON to the Bundle.
The benefit of CoreData is you could query relationships, such as get a brag sheet of which of my video game characters are in my friends library, but at a higher level and played for fewer hours but collected far in the past. In a large dataset, CoreData will be faster than looping over arrays yourself. But for a smaller dataset like yours may be, again, it may not matter really at all.
I'm building a note-taking app with lots of cross-ways uses of entered text. In this case, CoreData was easier than managing all those relationships in JSON, which makes the extra function calls to manage CoreData CRUD calls worth it.
Also, you may want to ship the JSON with your app and then call an updater on launch. This way, in case the API changes, your app isn't immediately broken until you get around to updating it.

Xcode 8/Swift 3: make API information available offline? [duplicate]

This question already has an answer here:
How to make offline database for my app?
(1 answer)
Closed 6 years ago.
I'm currently working on an application in Xcode 8/Swift 3 which runs through APIs. Essentially, I'm parsing information using SwiftyJSON from my MySQL database which keeps the content current and easily updated.
To keep it so the content is also available offline, I'd like to introduce a facility where the data is downloaded and stored on the phone so it is available in "offline mode".
I know it's a completely open question but can anyone point me in the correct direction of how I could make this JSON information available offline? I've tried searching the net with no success.
I know it's not Swift, but the absolute master of this has recently open sauced his master piece: Dash for iOS.
Reviewing what he's done to get rapid scrolling and searches might give some deep insight into how to best do this as done by someone with (arguably) more experience in this area than anyone other than Apple:
https://github.com/Kapeli/Dash-iOS
I will prefer here 2 option either I will go with 1.SQLite DB or 2. NSURLCache
For SQLite DB you can use FMDB wrapper-https://github.com/ccgus/fmdb
For NSURLCache check this link Best way to Cache JSON from API in SWIFT?
If you just want to save json then go with NSURLCache for offline mode.
Achieving offline for iOS is having two best paths they are CoreData and SQLITE. As per the definition of CoreData suggests it is a Model layer of the project. It comes with less efforts on developer side. Bit contrast SQLITE having the same way but little efforts on it.
In my project we are using the CoreData for offline maintenance. Really we have few concerns on the Relational data fetching, Although there is a Predicates representing CoreData for the same still it is limited to some part. These type of situations SQLITE is really a life saver. We can easily fetch the records with simple JOIN commands.
Conclusion:
If you have more complex data relations it's really better to go with the SQLITE, Apart from CoreData is best choice.

How can I get Core Data in a project that did't check the 'use Core Data' option at start up? [duplicate]

This question already has an answer here:
Implement CoreData into an existing project using Swift
(1 answer)
Closed 7 years ago.
When I created my project, I'm new in iOS development, so I did't check the use Core Data option, but now I need to use Core Data in my project and I've already put a lot of work on the project so I can't start all over again. So anyone knows how to get those files like coredata.xcdatamodeld?
I don't know the exact solution to just adding Core Data to a project without Core Data but instead of using Core Data use SQLite. It can be implemented to your project
Let’s take a look at using SQLite directly.
Relational Database System
Potential for cross platform compatibility
Many early iPhone database examples were written using SQLite
Objective-C wrappers such as FMDB are pretty easy to use
Now at Core Data:
Can store data in it’s own Binary, or SQLite storage format.
Can serialize objects – Much higher level than using SQLite
directly
Not a RDBMS you could actually just store things directly.

guidelines from a pro for IOS 6 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
i would like to know or maybe if someone can guide me what to do. for now im putting my mind on creating an app that gets the featured products on my website, using storyboard. where i click on products on my list in the tables view the it'll send me to next view to choose the product and when i click on the product and it'll go to another view where its details are written. i would know that it'll be done with parsing, or am i wrong.
its like, products --> products name list from web --> details
the interface and the tableview are already set, coding is just missing i just need to know where to begin.
Just a heads up, this question is far too broad for StackOverflow. You need to break this up and ask several smaller questions.
User Loads app, and it makes a request to your webserver asking for product list
(NSURLConnection)
Webserver receives request and sends encoded data back down. XML? JSON? Up to you.
(What software is running on your webserver? PHP? MySQL? Gather data and encode)
App Receives product data. Parse the encoding wrapper to get your object data.
(JSON or XML to NSDictionary, some good libraries available)
Populate data source with this data
Display data
If you have hundreds of products you'll probably need to reproduce this over and over, but that's up to you. If you only have a dozen or so it's probably easier to just send the whole chunk over on app startup.
Ace, if understand you correctly, the products itself should be fetched from the server. Then you can pick one or display the details. So, I would use a framework to connect and get the results from the server. There are things to consider: XML/JSON data parsing and mapping, Storing and caching the products, so you would be able to display them when there is no connections and updating with the latest changes. I am currently using RestKit which handles pretty much all of these things but for JSON. If you consider CoreData (database storage in iOS) you may need some additional help with retrieving the objects - MagicalRecord framework (on top of RestKit). It will handle things like findAll, findByAttribute:name: so you can get the objects you need. These frameworks are somewhat advanced, but on the other hand, they provide a sound ground for the UI stuff.
When you set up the backend integration and get your objects/collection of objects into the client, you can start populating the TableViews and displaying details.
One more thing to consider for a new project - CocoaPods. It is a very nice way to manage third-party libraries and frameworks. You just specify the libs you need and their versions (the good practice is to always specify the version, so the libs stay in sync) and it will fetch them and create a XCode workspace with them, so you don't have to worry about integrating them into the project. Both of the frameworks are there, just use
pods search <your_framework>
Good luck

SQLite or coredata or other [duplicate]

This question already has answers here:
Use CoreData or SQLite on iPhone? [closed]
(3 answers)
Closed 9 years ago.
This is for an iphone app. What's the best route that I should take? I have data and I would like to have it in my app and access it throughout the app in different ways search, title, state, etc.
I don't want the user to be able to modify it or delete it.
Should I use core data or SQLite or is there a better way?
Thank you
I personally would recommend using CoreData for its ease of use. CoreData, in fact, act as an abstraction layer over SQLite so, you don't need to actually write any SQL lines.
Take a look at the CoreData documentation from Apple so you can understand exactly what it is. Or, maybe, you can jump to their Tutorial for a "hands-on" explaining:
Core Data Tutorial for iOS
Also, I personally like to use tutorials from the Ray Wenderlich sites, like this one:
Core Data on iOS 5 Tutorial: Getting Started
(by the time of writing this, the Ray Wenderlich's site is under maintenance.. but check it out later.. it is pretty good!)

Resources