How to save sign up api response and pass the data in the response to profile screen - swift

In my app how do i save signup API response i.e userid,username,email,profile image and once sign up successfully it takes me to profile screen . How do i show the saved response in the respective field in profile screen controller. I am using alamofire for parsing and have also created signup data model. How can i save with swifty user defaults library

You can use Database (Core Data, Realm, ...) or UserDefaults to store data.

You can use userdefaults for saving your username,userid,username,email. If you have profile image as url string, you can save it in userdefaults and call it on image in your profile screen too. If you have profile image as an image, may be you can cache it or save it in a singleton class. Storing process can be multiple so you have to choose it depending your business of app.

Related

how to pass http api data to anther page?

I was building a demo application for a store (not a specific one) and I got the data from an online JSON file through http requests, is it possible to pass the data to another file?
I tried to pass the data using an object from the where I extracted the data and using sharedPreferences too expecting to pass the data to the other screen and display it, but the actual output was nothing.
you can share data from one page to another page using arguments property of push method
Navigator.of(context).pushNamed("routeName",arguments: data);
to extract this data in the second page use this
ModalRoute.of(context)!.settings.arguments;

SwiftUI & Firestore

I am wanting to use Firestore to retrieve user info and other data linked to that user once they have logged in via firebase auth. On the home page of the app I use .onAppear{ pulluserData() }. I understand that Firestore functions are asynchronous so how can I wait for this data to be pulled before displaying it to the user on the home screen?
Here is my function to check the database:
func checkDatabase() async {
//Function that will check the database. Will be good to add a listener eventually
if self.pullUserData{
await dbm.readUser(userID: "VSWAq7QCw3dbGYwMdtClbbANGVe2")
}
}
and the actual database function:
func readUser(userID: String)async{
//Function that will be used to read user info from the database
let userRef = database.collection("users")
do{
let doc = try await userRef.document(userID).getDocument().data()
print("The doc is: ")
print(doc as Any)
}
catch {
}
}
There are a number of ways to do this but the two most common ways are to (1) use a launch screen to indicate a loading state that disappears to a view identical to the launch screen (to continue the appearance of loading) that is only removed when the database returns (i.e. Twitter); (2) load the user right into the app and allow them to move freely while either indicating that data is loading or displaying cached data.
Remember that Firestore maintains a local cache on the device which means that data will be available immediately when the app launches. This data may be out of sync with the server but it will update as soon as the app establishes a connection with Firestore, which is usually instant. What I would recommend is launching the user right into the app without the use of a loading screen and relying on the cached data to get the UI up as fast as possible.
And if we're only talking about user-specific data (data that is specific to the user that the user has full control over) then that data will only change when the user changes it, which would have been the last time they used the app, which means that the locally-cached data on their device (assuming they use only one device) will always reflect the state of the server (in theory, anyway). And if it doesn't then it doesn't; the fresh data will update instantly anyway.
You may then wonder what happens if the user launches the app without connection. In that case, the cached data is displayed and the user is almost none the wiser. And because Firestore is offline capable, the user can freely edit their data and it will write to the server when connection eventually establishes.

Displaying each user's profile picture from Parse in their respective tableview cells (Swift and Parse)

I am trying to display the profile picture of the author for each post in the tableview using Swift and Parse.
The view controller at hand is querying one class (Post class) from Parse to obtain all the contents of a post. However, only one of the contents of a post (the profile picture which is of type File in Parse) is stored in another class, the User class, because each user has a profile picture.
Each post in the Post class has a foreign key (to represent the author of the post) which points to the User class.
How can I access the photo column from the User class from a pointer in the Post class?
The reference from the post to a user should be a pointer. Then, the query can specify to includeKey with the name of that pointer to have the user included in the results of the query so you can access its details.
The above requires public read permissions on all users. If you want better data security you need to do the above in cloud code and return only the required data.

Using Restkit and Core data to Retrieve Images

I have a core data application using rest kit to retrieve data from a web service. The response i get from the webservice is a json string like this -
"nodeRef": "workspace:\/\/SpacesStore\/b1d51831-990d-47a8-a018-f1c1bg33f594",
"type": "document",
"name": "x.jpg",
"displayName": "x.jpg",
"title": "myTestProject",
(This is some meta data around an image. If i want to retrieve this image then i should access it using this url - http://x.co.uk/share/proxy/alfresco/api/node/workspace/SpacesStore/b1d51831-990d-47a8-a018-f1c1bg33f594/content/thumbnails/ipad1024?c=force) - note ive changed the URL slightly so you wont be able to access it. Also you need to authentication to access the URL. So i was wondering how i would go about getting this image and storing it locally on my SQLite DB? I can obviously access the URL but how exactly do i prompt it to download the image
What i did in this situation was to do a lazy load on the image with something like:
image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.absoluteUri]]];
NSData *imageData=UIImageJPEGRepresentation(image, JPGCompression);
Then store it. Outside of Restkit. This was a while ago, but it worked for me.
Basically extract the URL from restkit, do a lazy load when the image is presented on the screen, and thne store it back to core data (or wherever) when you have loaded it once.
Hope this helps.

iOS: How to save data over the complete lifecycle?

I have an iOS app with a login view.
I need to have the login-data the whole time until the user ends the app or click "logout".
How and where to store it?
Are something equel like "member variables" possible in iOS / objective C?
If you're going to be storing username/password data, it's probably best to store it in the keychain. If you're only looking to keep track of whether a user is logged in, then consider storing a flag of some kind in NSUserDefaults. You can clear data when the application exits through the applicationWillTerminate: method of your application delegate.
You could use NSUSerDefaults, but everything you save in NSUserDefaults stays there for ever unless you delete it. Id I understand i right, you want that the password ans login gets saved only when the app is opened, and when the app is being closed, that data gets deleted? With nsuserdefaults you will have to set #"" for the password and login in applicationwillterminate, to delete the data. Or you declare two NSStrings in you header file, and in the .m you do passwdstring = passwd.text
loginstring = login.text
what this does is it saves the data to two nsstrings, that data is available the whole time while the app is opened, when the user closes the app, and re opens it, the strings are nil again and when he logs in, the strings will have the loging info again.