How would you save user's profile data from firebase in cache Swift - swift

I have a view controller that is basically the average user's profile on any social media app (showing data like their name, followers, following, name, bio and profile picture). I have successfully made it so all the relevant data get's retrieved from my firebase database.
However, whenever I go out of that view controller and back in again, from the profile screen to a post and back to their profile screen, it reloads all the data again which caused the hard coded values of the profile like 'Name' for the name label to show every time they go out and back into the view controller.
So my question is, how would I retain all the data in a cache - I guess, so it looks like its only loaded the data once (obviously in the background it will check for a change every time you reload the view).
If i'm correct you can solve that problem for string based values (like their name and followers number) by using the firebase offline capabilities? How would I do the same for stuff like their profile picture? Save the picture in a cache and then update it whenever there's a change?
Thanks,
Nathan
EDIT: Here's a video of my problem: here as you can see in the video, when you go back out of the view controller, and then back in, the image has to be loaded again. Is there any way to save that imaged to a cache so the next time the profile is opened it will already be there.

Related

How to get user input with UITextView in different cells in UITableVIew

so I have a UITableView and within each cell, a UITextView. I want the user to be able to edit each UITextView as many times as they like, then go back to somewhere else in the app, close the app, whatever, and then come back and see the same thing they wrote. I have not been able to figure out how to do it.
Please help. I'm still pretty new to Swift.
This is a design problem. Anyway my suggestion is to add a flag in your data model.
Data model (the data that you are presenting in your table). If you don't have any data model, add one.
Example:
class UserInformation {
name: String
isEditing: Bool = false
}
and then save this in your preferred location either in DB (core data, realm etc) or plist (which i don't recommend)
now during the creation of cell. You could just check if this is in editing mode. And then fill up the text field using the saved data.
EDIT: You can't just magically know/retain a state in an object without persisting.
You want to store textView informations in any case, including terminating application, there are some steps to implement this feature.
At first, you have to pick up a place for storing your information:
Hard disk
Your own server
Other service (firebase ...)
RAM is not useable in this case.
Supposing you like hard disk option, let's select a method for storing:
Create a file (JSON, text file, ...), save your information every time user enter a new one, open it to get information back.
Save it by CoreData / Realm in database way (CoreData is like SQL lite, a lite weight database for mobile application supported by Apple)

How to use the 'didSelectRowAtIndexPath' for displaying photos from a particular album

I have setup a table view that displays users albums from the device. I'm using ALAssets to populate the table view.
Now how do I display photos from the particular album in another view?...
I have seen tutorials regarding NSDictionaries... however it needs the 'keys' and 'values' to be fixed... then it loads the corresponding data.
But is there any other way to do this..., a more dynamic one sort of... since the album names might not be same in each user's device...
The simplest way to go is to use a navigation controller and push a new instance of a view controller (a new one dedicated to showing albums or a new instance of the same one, depending on preference). That view controller you give info about which group to show, and potentially also hand it the AL stuff.

How can I save a website in Cocoa Touch and store it in an array?

I am just building an app for my first time. I've created it so that I open it and it opens web view and I have a button called "Save" (so it's just a web view inside the app with a little button below it). I would like to be able to save a website when I visit it. It doesn't need to label the save or anything, I just want it to save and I can click another button called "sites" and it will display my list of saved websites.
You will have to decide on some kind of storage method. A simple one would be create an NSMutableArray of the sites. Depending on the needs of the application, you could change this to something different. Then, saving the site is as simple as inserting an object that represents the page (maybe an NSURL or an NSString with the URL). The question Get current URL of UIWebView discusses several ways of getting a URL from a webview. You can then decide on a way to display the list of saved sites. Once a site is selected, you just have to pass it back to the webview.

GWT Place objects

I'm new to GWT so this may be a dumb question but I didn't find a good answer to it anywhere.
So, how should I create Place objects in GWT? Should I create them as finals in my ClientFactory and reuse them everywhere?
the Place objects Eclipse generates eat a string token as their parameter what should it be?
My Understanding is the following: I should create final Place objects in my ValueChangeHandler for those pages that are static and reuse them everywhere. Those 'Place's that are relatively dynamic should be created like
new MyCoolPlace("MyCoolPlace" + someRandomNumber)
but isn't it kind of dumb using random numbers each time i need to navigate to a new page? also will the history be cleared of the objects which i created say hours ago?
Currently I have a problem with figuring out how this mechanism works:
I have a form. For, say, adding vegetables to the DB
1. User fills it
2. Submits it
3. Gets to a thank you page
4. Clicks a link in the menu to add a new vegetable
5. Gets to the form but it's already pre-filled with the values user previously entered.
I need the form clean on step 5. But if the user clicks the browser's back button on step 3 I want it to be pre-filled.
Question about final:
I think not. They are lightweight objects and places can have values into them. They are not a limited set of places values (at least if you parametrize them).
Question about form values:
The normal behaviour is when yo go back to -let's say- "vegForm" you obtain the clean view (it's because your URL token is simple vegForm). What happens I think it's you're reusing your view without initializing. Your presenter (or whatever has the UI logic) should obtain the view and call "reset()" "init()" or whatever you want.
If you want to hold your values when you go back you should save them in your place object. It is: field values. And your PlaceTokenizer (the object that transform between URL and Place object) should take care of them. By example: vegForm/potato,green,... (don't remember the standard notation).
The problem is how do you save into the URL the values you entered before clicking Save?
What I'd do is "saving" that state into the URL before saving:
History.newItem("vegForm/potato,green,...", false);
And that will get into the history stack. When I say false it means that the GWT History mechanism should not react to that URL avoiding loading the view again. When your user clicks back she should go back to form(with values). If your user clicks back again the she should go back to form(clean).
By example:
User clicks add veg -> #vegForm
User fills data and pless save
-> #vegForm/value1,value2 (saved in History with false argument)
-> #okPage
User clicks back
-> #vegForm/value1,value2 (form with saved data)
User clicks back
-> #vegForm (form without)
Initialization
Take into account you always must initialize the view.
If you don't have params, to clean it (it can be a reused view)
If you have params, to fill the form with them

Serialization with objective-c

I'm doing a iphone application and when the user quit the application and return in the application later, I want he return at the same place in the application before he quit. How I do this? Is it serialization?
thanks
Alex
It's a little different than serialization. What you want to do is save the app details in NSUserDefaults. For example, if you have a tab view, save the index of the last tab used in the user defaults.
If you have a table view, you can use serialization to save the actual information in the table to present back to the user when they start the app again.