Saving screenshot to CoreData - swift

I'm developing an app that I want the user to be able to take a screenshot with a button (this works, but it's stored to camera roll). I have a need to keep history of these screenshots along with site name, etc.
I've been reading that it's not recommended to save binary data in a sqlite db, so I've stumbled across core data. I'm still learning, but one question that comes to mind is this. Some recommend to save the filename to coredata and then save the image to document directory. I want to read the data back into a table view controller and have the image part of the cell. Will I need to resize the image to the size I want when reading in, or will it automatically size down to what it needs?
Also, when saving to document directory, are those files accessible from the camera roll? I don't want them to be and I'd like to give the user the ability to be able to delete them with the tableviewcontroller.
Please let me know if I need to expand on anything. I'm learning Swift, so I'm sure I missed something.

You should not save it to the Documents directory.
You should instead Allow External Storage of the attribute. Core Data will take care of storing it for you. This is explained in the answer by jansenmaarten to this question.

Related

UITableView survey app and append data to apple numbers

Ive tried to search up documentation and several tutorials but it seems like there's nothing out there. Maybe this is something simple to do, but I just cannot figure it out.
My goal is to make an application that has a series of questions that you fill in. Some tick boxes and some text fields where you fill in some more info. This survey would be on one VC and you scroll down through the questions. After all this I want to append the data to the apple numbers app on the iPad with a specific structure.
How would I go about this? Any resources you can recommend?
T.I.A
I believe that you should generate and export a .csv file with all the data you collect in the app. Save that file to iCloud Drive or to another cloud solution you can integrate in your app, and then access it and open it using Numbers.

How to store data localy in swift osx app?

I'm working on my first osx App and I want to save arrays of objects that I've created on a "project file" like you do in any program when using the "save" button.
I have been looking different ways to do it, Core Data, Document based app, but, I'm not sure how it works any of them to choose the best option for my app.
I want to save arrays of objects that have inside more arrays and other strings and doubles that contain information of the app that the user added. ( It can be a lot of data ) So for that reason I think Userdefault is not a good idea.
I also want to make the app able to open one of this projects saved.
So, could you help me to find which is the best way to do it?
I can suggest you to read iOS FileSystem Overview.
You must use the Data container to locate your local files. For this, you have to locate the NSDocumentDirectory with the NSUserDomainMask (call to NSSearchPathForDirectoriesInDomains) and use standard NSFileManager class.

Store Image path in database

I am making a app in which I am retrieving data from Database in List View.
I want to have different picture with each data I retrieve from database in list View.
What I am trying to do is to save my pictures in drawable folder of my app and want to save image path in database and retrieve my image from saved path.
I searched lot on internet but couldn't get appropriate solution.
Somebody please show me appropriate code.
Don't know if you already have solved this problem,
but after looking for it myself i found a solution.
what i did was use this.
i stored my images in a subfolder in "Assets" and this works like a charm,
don't know how many images it can hold in total, but i'll find out eventually i guess xD

coredata as front end and text files as backend

How does this sound conceptually.
I wanted to store some text and add tags to it thats easily retrivable. Coredata is the obvious solution, but i also needed that data across the cloud, not just iCloud like dropbox. So I thot i'd use Coredata + textFiles.
obvious approach
use coredata with two entities. One for text and one for tags. Works awesome BUT not ready for syncing.
1. using icloud coredata combo will hurt me badly, its still unreliable, and i cant afford to keep stabilising it.
2. i dont just have ios devices, need it on my computer too.
the solution
Add text in a simple textview.
Add tags to the text as well using some kinda delimiters.
Save the document as a text file (that includes tags) and give the document some unique name
Put that file in dropbox or icloud or whatever as a document But Also, parse it locally in the iOS app so that the text in file is separated into text and tags each of which enters its entity in coredata.
advantage for the solution
I can use the text in a useful way locally (in iphone) and if needed will get those text files from the cloud.
problem with the solution
Data in the cloud (as textfiles) is only so useful. But nonetheless, its there, i can live with this.
SYNCING: how do i make sure that each file is synced appropriately. Im not sure I should use UIManagedDocument? I'm already using coredata locally, dont know how i'd complicate things if i use UIManagedDocument.
My question is, im confused about the syncing and saving part, what should i do to keep it neat and clean.
While writing this question i feel like I screwed up the whole idea.

Where to store a preview of a UIDocument?

I'm working on UIDocument application and I'd like to show the user a preview of the document before he opens it. I can render that preview into an image when the document get's closed. But where should I save that image? In an other file? or is there a designated way to do this?
Right now I'm developing it without iCloud support. But I want to have a solution that would work with iCloud too. The UIDocument is a UIManagedDocument. But saving the image into the database would make it kind a pointless. Because then I have to open the document before I can get the preview.
What do you recommend here? Where to put a preview for a UIManagedDocument?
You can store your documents in your ubiquity container's Documents directory and document preview files in the container's Data directory.
If preview file names will be based on the documents names you will be able to use metadata query result to get the document names and then resolve document preview urls.
This way you could download the document previews only but not the whole document.
I don't know about UIManagedDocuments, but in case of a UIDocument I would recommend using a NSFileWrapper as file format (where the document is actually a bundled folder) and save the preview within the document, as "Preview.jpg" (or .png) inside a folder labeled "QuickLook".
This way, you'll get the preview in Finder on the Mac as well (for free).
Of course this may or may not be an ideal solution (also depending on if your document is text-only). But it might be a good hint for working with previews for UIDocuments in general.
You should save an image under (app_directory)/Library/Caches. That way iCloud won't affect your app.