Add Multiple Images as PFFiles to Parse Array - ios

basically I'm struggling with this:
I installed an FacebookAlbumPicker (https://github.com/OceanLabs/FacebookImagePicker-iOS)
Now I try to upload these Images to my PFObject PFUser.currentUser["images"] which should be an array of PFFiles.
Later I want to retrieve them.
When uploading to parse (just one photo for) it gives me a strange documentation of it:
images:array => [{"__type":"File","name":"tfss-c5f07d1f-34a3-4041-bc18-e13237abd077-file","url":"http://files.parsetfss.com/f84a8fda-4aff-45dc-b328-8e46987c191f/tfss-c5f07d1f-34a3-4041-bc18-e13237abd077-file"}]
How can I access this inside CollectionviewCells now?

You cannot store PFFile-objects as Array. Create new class in your Parse app like PhotoObject and there create column file. Then in your User class create column photos which will be array of pointers to PhotoObject class.
And when you want to get images of user you query for photos.

Related

Showing random data from core-data using Swift 3

I need some help getting random data from core data using Swift 3, Xcode 8.3.1. I currently have an app that creates a list in tableview using data that is entered by the user.. (user enters a name and takes a picture of that person) The entity "Friend" holds the attributes "name", "image".
The first version of this app was just a name and I would use arc4random to randomly update a label with a name on a modally presented VC on a button click. The names were simply stored in an Array.
This version is including an image so I decided to try my hand at core-data (never used it before) and now I'm stuck at my random select button. Currently the app will store the data fine and then retrieve it and display everyone alphabetically along with their image in a tableview. As a new person is submitted the info gets stored and the tableview updates.
I need to show a randomly selected name and its image, but I don't know how to do this and research has failed me on getting it done.
If there is a better way of storing an image & name instead of core-data I'm open to changing as well. The app stores anywhere from 20-80 different names. It will never be used to store much more than that.
You can fetch your items from the context, which will give you an array of objects. Now you just use your favorite random function to get a random index for this array. And then use an object at that index.

How to add another column to my class in Parse.com? (Swift)

I am having some difficulty adding a new column to my class in Parse. Currently I have made a class (named: Venue Data) with the name and geopoints of restaurants. I would like to add to that class a column for image which will be paired respective to the specific restaurant. I am quite stumped as to how I should go about it. Any help is greatly appreciated.
Parse allows you to add columns to a class lazily, meaning that you can add a field to your PFObject and if it is not present in your Parse class, Parse will add that column for you.
Here's how you would add a column via code:
// Prepare image
let imageData = UIImagePNGRepresentation(yourImage)
let imageFile = PFFile(name:"image.png", data:imageData) // "image.png" is the name which would be shown on Parse.com
// Add the new field to your object
yourObject["image"] = imageFile
yourObject.saveInBackground()
You'll notice that Parse will create a new column named image on their web portal.
If you log in to Parse and are in your data view ("Core" should be highlighted at the top), you should have a few options that look like .
Click + Col and that should give you a new column to add!
If you're talking about how you would go about adding images specifically, I would store the URLs of the images as a string in Parse and load asynchronously the images in your app.

List of images with their properties

My problem:
In my app there are a lot of images. I have a list of categories which user can choose for filtering all images by chosen category. User can't delete/edit these images, and can't add smth in it, so I guess I don't need the Core Data.
So my question is:
How and where in my project should I store and manage images' names with their properties, so I could use this list with files' names and their properties from any ViewController?
Finally, if you didn't get it: It should look like this:
1.Name: "imagename.jpg", Category: "Somecategory")
2.Name: "imagename2.jpg", Category: "Anothercategory")
Thank you.
If you want to store your images under NSDocuments with a susbfolder , I think you can do it without using database and Core Data .
Let's think a scenerio for you based on Model View Controller(MVC) structure:
You want to store images with an special properties like NSString *categories and NSString *filePath under NSFileManager with a subfolder . Encode your object and convert it to NSData. You need an Model class(it's subclass of NSObject)
that keeps your properties. You need to learn how to save a file to your Documents path. This blog is very good but it's Objective C. This is your Model and your image object.
Create a View that shows your images UICollectionView (just an example) and collect them with your image object. Modify it how you want!
Create your Controller class and do all actions here. Like saving image to path, getting image from path, all UIButton actions etc... Add your View to this class,decode your NSData to your image object show it.
This is the logic of an example, you can do it according to your necessities.
The way you should following is saving your image data to NSDocuments , search it. I advice you to learn MVC Stucture
Hope this give you an idea to start.

Parse, How to send array entries as multiple PFObjects, Create a new row for each array object

I'm using Parse as the backend for my app. My app will be used in the field where service will nonexistent or spotty at best so I need to store information offline. I currently save data for the user in a plist in the background (Title, location coordinates, notes, additional data). Since Parse's current iOS offline saving is fairly poor (From what I've read), I was hoping to get around it by creating an array or dictionary from the plist and upload that to Parse by giving it an array once the user is back in cell range.
As it occurs now, when I upload the array, it simply puts the entire contents of the array in a single cell in the database. Is there a way to parse the array and create a new row for each entry/object in the array?
I may have overlooked a better way to do this. If someone has a suggestion I would appreciate it!
I solved it. I iterated through the array using a for loop and added each index as a separate object.

Storing a persistent array of UIImages - CoreData or on disk?

In my app I will have an array of up to 50 images that people can maintain. They can choose to create new or delete existing images. Each image will have a few things associated with them, like a rating for example.
My question is how I should go about storing them. Should I create a CoreData entity called "Image" and store them that way? Should I set up a UIView subclass that conforms to NSCoding and just encode and decode the array and store it on the device? Is there another way I should consider? Thanks for any suggestions.
You can create an entity that represents the image with its information, and use core data's external storage property for entity's attribute. This way, you get the convenience of core data without actually storing the images on the persistent store.
I had to make a similar decision recently and I decided to store the image in CoreData. I have a managed object called photo with a Binary Data field called image:
photo.image = UIImagePNGRepresentation(imageFile); // <- imageFile is a UIImage
And I recreate the image using:
[UIImage imageWithData:self.image];
One immediate advantage is that the images are deleted automatically with the object and there's no extra overhead in retrieving the image if you've already queried for the record.
Core Data is probably overkill for what you want to do. Choose some key value pairs for descriptive information about the image. One key will be "path" and the value will be the path to the image file (or just its name). You can serialize array (or set) of dictionaries.
When your app starts up, read in the serialized array of dictionaries. Every time something changes, serialize and save the information. Write a short audit routine to insure that there is a one - to - one correspondence between dictionaries and images on file, and if one or the other is missing delete the other (will handle situations were you crash before getting to update something or the other).
Later on you can add more attributes to the dictionaries if you want, or even remove some.
[PS: I did this in a shipping app for one version, when the information needed to become relational I switched to Core Data.]

Resources