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.
Related
I have made a small app that uses Parse, I have a signUp viewController, and after signing up I have a usersVC viewController.
Inside Parse dashboard I added a column named profileName, I want that after signing up to grab the value that is inside this column to some label.
Here parse dashboard:
enter image description here
I mean I need something like: profileNameLbl.text = PFUser.current().profileName
but of course this wont compile.
On swift 4.2 use:
PFUser.current()?[“profileName”] as? String
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.
Assume we have simple data model with single entity User; simple tableView_friends with fetchedResultsController_friends for show users - friends.
Assume we have search bar for searching all (not only friends) users in service, and for every typed in it character we perform search request to server, which return to us somehow filtered by character User objects. Some of this objects can already be inside local database. By app logic we don't really must save all this results in local database forever (but ok, we can, we can clear local database time to time); on other hand, if we will perform any action on some searched user, we must store this user. We want to show list of searched user in other tableView_search with fetchedResultsController_search.
Question: should I use same context for fetchedResultsController_friends and fetchedResultsController_search? If no, how can I handle situation, when I wish to edit searched user, which already exists in database and probably already local edited? If yes, how can I setup predicate for fetchedResultsController_search (server perform its own logic for search by character, which can be changed) for show exactly same result as from server?
We recently implemented a search feature in our application and had a similar issue, We had local data in core data and also remote data from our API.
You have a few options that we explored:
Save your data into core data from the API as it is retreived and
then the fetched results controller will do the rest
Manage the merge of the data yourself, you can still use NSFetchedResults controller to an extent but need to do more work
We didn't want to save all of the information returned from the API unless it was needed (the user selected it), so we come up with a simple solution that worked for our app. This may not work directly for your app, you may need a completely different solution or change some of the things we done to suit.
Firstly, To explain what we are dealing with, we had a Article entity in core data which contains around 25 properties, the API returns article objects as JSON data with the same data.
What we decided to do was to create a class which represents a simple version of an article (just enough data to show in a list view and reference it later in the API or core data) which looked something like this:
class SearchResult: NSObject {
var id:String?
var title:String?
var imageUrl:String?
var url:String?
// core data entity
init(article:Article) {
self.id = content.contentId
self.title = content.title
self.featuredImageURL = content.absoluteImagePath()
self.urlAlias = content.urlAlias
self.publishedAt = content.publishedAt
}
init(articleDictionary:NSDictionary) {
self.id = articleDictionary.objectForKeyNotNull("id") as? String
self.title = articleDictionary.objectForKeyNotNull("title") as? String
self.url = articleDictionary.objectForKeyNotNull("url") as? String
if let imageUrl = articleDictionary.objectForKeyNotNull("imageUrl") as? String {
self.imageUrl = imageUrl
}
}
}
Now using this, we can create once of these from either the core data results or from the API results. Our tableview datasource is just an array
var dataSet = [SearchResult]()
We use the NSFectchResultsController delegate methods to add/remove/re-order core data elements from the dataSet after the initial load and when we get API data we'll do something like:
dataSet = Array(Set(apiResponseArray + dataSet))
This will take an array of SearchResult items from the API, merge them with the current result set and remove duplicates. casting to a set and then back to an array will give you an array of unique results as a Set is made of unique values only.
See this reference which should help with how the delegate methods would work
enter image description here
Attached is screenshot for my view controller. When users search on internet, how do I realize these functions?
save current web page ( maybe go to another view controller after clicking "save")
my idea is to save on a table view, with a brief title
after clicking the title, shows contents of the whole page saved.
if users reply emails on some website with attachments, they can also save the attachments (word, pdf,etc) in the app.
I initialized the web view with google. The problem is the page to be saved can be any NSURL, I have no idea how to do that.
Or you can advise some way totally different, as long as I can realize these functions.
For future reference you should include some code... but anyway, I would just set the NSURL as a string of each webpage in NSUserDefaults then call the main applications open URL method.
Like...
NSUserDefaults.standardUserDefaults.setObject("YourURL" forKey: "URLKey")
NSUserDefaults.standardUserDefaults.synchronize()
Then retrieve it like...
if let urlString = NSUserDefaults.standardUserDefaults.objectForKey("URLKey") {
let url = NSURL(string: urlString)
UIApplicationSharedApplication.openURL(url)
}
I wrote this code off the top of my head so it might need some tweaking but I hope it helps!
If you want the user to save many webpages, you should not use NSUserDefaults to achieve it. You should use something called CoreData. This is because NSUserDefaults can only save one url at a time. If you want to save another, you need another key to do so.
Here is basically what you need to do. You create a new Core Data Model file (.xcdatamodeld). Add an entity called SavedUrls. Add a property to that entity called urlString. Then generate a NSManagedObject subclass.
To save data, get the managed object context from the App Delegate. Create a new instance of SavedUrls using the inherited initializer. And change the property to the url to be saved. Then just call save on the context.
To get data back, get the managed object context and create an NSFetchRequest to fetch from the database.
Learn more here:
https://www.raywenderlich.com/115695/getting-started-with-core-data-tutorial
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.