save to local storage swift - ios

I am designing an idle clicker style app, as I am quite new to programming and thought it would be a good personal project. However I am trying to design the upgrades on a second ViewController menu, however every time that the user leaves the first ViewController, all the settings on that page are lost e.g. stats. I know that there are already similar questions, but they don't relate to my issue and I am having difficulties trying to understand them.
I was just wondering if someone had any way to save this progress both when the user moves to a new viewController and when the app is closed and reopened. Also this might be pushing it, but if you could describe what each part of the code does it would be very helpful.
Thanks

Best is to use UserDefaults to store page contents. You can define key/value pairs and save and load values as needed. Look for it in the IOS documentation. It is very easy to implement it.

Related

When to Use CSV from Web or Keeping Data in Xcode?

I do not believe this has been asked before so please be easy on me.
I plan to have a flashcard app that when pressing the "next" button, will cycle randomly through them. There will be different categories for different topics which will be accessed through a relative UIButton.
I could add all my data as code in Xcode of course, but the only issue is that when a new flashcard is created the user will have to update the App via App Store.
I have found bits and pieces of information regarding JSON and CSV files and pulling that data from an online source, however, with allowing the user to press a button to randomly cycle through what will be essentially TextViews, I have hit a dead-end on finding if this is an effective option or if there are better options. I also struggle to find information related to imported to Xcode, however, there is more than enough information on exporting from Xcode to CSV.
Thank You!

iOS background tasks synhronization app flow

I'm programming in iOS not so long. I was mainly programming UI related stuff like animations, custom UIControls etc.
I need in my new app to:
Display loading activity indicator and in the same time:
load some remote data from server parse them and store in local core data
load some data from local core data
get user position from location service
After this I have all data needed to display next view controller and dismiss loading indicator.
Question is how can I do this all? I need to support iOS9, iOS10, 11, 12. I understand that this needs to be done in background threads and then I need to merge all data from each task and switch to next view controller. I can't use any external libraries like rx-swift or promise-kit. Maybe there is any experienced iOS developer who can give me some main guidelines how to approach to this kind of application flows? I can imagine there is a lot of ways I can do it some of them are better and some of them are worse. Any guidelines would be very helpful for me. Thanks.
It's a very complex question and as you said it's possible to solve all this problems in several ways. But for sure i can give you some core-hints about which steps is better to follow:
Run in a separate thread the management of all stuff regarding to the Network communication. Maybe you can run it on a separate queue using the class DispatchQueue(). Once you received the data, in the same thread, maybe you can directly convert these information and store them inside a CoreData database.
To store into CoreData you need at first to know how it works, so basically search for some really easy tutorial about how to create from zero your first database inside XCode. After you have been able to run and execute a very simple one you will be able to pass to the second step and so try to integrate it with the data you have previously downloaded from the network. Here a good article for you: https://www.raywenderlich.com/7569-getting-started-with-core-data-tutorial .
To get the location is a separate field of study, because you have to study which background modes are allowed in iOS (And actually are allowed just a few). After that you will need to figure out in which category of background-location application your software belongs. After that you have to dig deep and discover how protocol and delegates works inside Swift/Objective-C in order to properly manage the last location value retrieved by the sensors. Here is a good article for you: https://www.raywenderlich.com/5247-core-location-tutorial-for-ios-tracking-visited-locations.
At the end when you interconnected all this flows you can think about how to display the loading indicator. Basically you need to drag and drop it from the tools into the storyboard, interconnect it by using the IBAction or IBOutlet, depending on when you wanna show it and in which specific case. And then use the relative method startAnimating or stopAnimating in the right code flow (It really depends on how you have structured all the previous bullet points).
Since your question was very general and it includes a lot of sub-steps, basically it really needs to be thorough studied and analysed.
I've tried to sum up as much as possible the most important bullet points. I hope the links i suggested to you will help a little bit. Good luck.

Flashcard app store questions and answers

I am creating a very simple flashcard app. It is a very basic app, the initial screen asks users to select a language. From there they pick from 5 categories. After selecting a category the user should get a random question (out of 20 possible questions).
My question is I want a question to not show up again within that set of 20 until all the other questions in that set have been shown. Similar to a deck of cards where the viewed card goes to the bottom of the deck.
The second question is what framework would be best for this application. There are 200 questions in total, all text, no images. My inclination would be to use something like core data or would that be overkill?
Any help on how to best implement this would be appreciated! I've attached a picture for further clarification.Storyboard Layout
You're doing a great job so far.
There are many ways to track your cards. The simplest might be to add a Boolean property to the card definition. Call it something like "hasBeenAnswered" and set it to false. As a card is retired you can set this to true. Refresh your data source after a correct answer by removing the card from your data source and also setting the book to true, or simply set it to true and replace your data source with all cards which are set to false. (Perform the same fetch you used to get your initial set of data: all cards where hasBeenAnswered is false)
On your second question I'd try to learn Realm. It's easier to pick up than core data, and as a cross-platform tool, you can leverage what you learn on iOS if you ever try to develop on mac or android platforms.
You can also refactor the project to core data after it works the way you want to. And learn even more.
The suggestions I've made are not the most resource efficient, but you won't have any performance issues given the size/scope of your project.
Good luck 🍀

Annotating PDFs: where to begin?

I'm taking a beginning mobile development class, and my professor wants me to jump right in and help him with an app of his written in Objective-C, and I have 3 months. I have taken a few other CS classes so far, but no next to nothing about mobile app development.
This app is basically a songbook that holds many PDF files of music scores. The first (of multiple things) that he wants me to add is the ability for a user to annotate the music score with highlighter, pen, and eraser. Since there are many music scores, I would need to have the app save these annotations for each score, and allow editing by the user later if needed (i.e. allow the user to go back and erase stuff and add more annotations to a given score).
I'm in the planning phase and I'm trying to figure out the best way to do this. I was thinking of having the annotations occur on a second view layer, and then saving that layer as an image so that it can be overlaid back onto the music notes sheet at any time (for the user to view). My concern is, would the user be able to re-annotate this layer once it has been saved as an image (i.e. erase and add more annotations, then save it again)?
Or what's the best way to go about this? I would really appreciate any advice because I am in over my head!
Well This is very broad question to answer it but let me help you with some links and you will need to go through that like.
It will help you to start your requirements into app.
There are many 3rd party frameworks are there for PDF annotations:
PSPDFKit (Paid)
FastPDFKit
Poppler (OpenSource)
There are some SO Questions links which also helps you for PDF annotation
Add Annotation to PDF
Annotation on an PDF
Programmatically add annotations on PDF
Some Github Links
LazyPDF
Note: LazyPDFKit - (No longer maintained - Use the source code to fix
the bugs)
Hope this will helps you in your research.

how to upload picture and event in my Published App Xcode 6

i am New user for Xcode in swift and i published my app to App Store. i could only connected with Parse ( Push notification Service )
but actually i want in future to change the background of my App or to add New Event. i know it is possible to do all this things with backend service but i heard that i have to design the code in parse, there is anyway to find the sample codes like push notification in Parse or somewhere else?
i will really appreciate if someone can help me.
"I want in future to change the background of my App or to add New Event"
These are hugely different scenarios.
Its pretty trivial to use Parse to change a screen background. Just save your existing background image as a file (eg as a UIImage) in Parse, and have your app download the image from Parse and set it as the background image of your UIView. Change the file and all users will see a new background. You would need to do this when the app loads (or at least before you access this screen), or else there will be some annoying delay when you access the screen with the new background image.
Adding a new event sounds close to impossible, as it involves modifying your code. But your compiled code is "signed", and as such is designed by Apple to be impossible to change without going through the market. Any app which could do that could bypass the market and potentially directly download malicious code. And nor (as far as I know) does Apple provide any support for extending or changing code within iOS. If its not actually impossible, I expect it would be so difficult and require so much knowledge of iOS as to be infeasible for the average programmer.
EDIT: You have now clarified as to what you mean by "Event" in your comments. This is just data which you load dynamically (and not an "event" in the programming sense). Yes you can do this through Parse (and lots of other ways), just read/load the data through Parse. Very easy to do, have you read Parse's excellent tutorial?

Resources