-2

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.

Marcin Kapusta
  • 5,076
  • 3
  • 38
  • 55
  • too broad. display activity indicator https://stackoverflow.com/questions/28785715/how-to-display-an-activity-indicator-with-text-on-ios-8-with-swift/28893660?s=1|35.7987#28893660 – Leo Dabus Nov 08 '18 at 23:58
  • next look for Codable protocol to convert your custom structure to data (json) and write the data locally – Leo Dabus Nov 08 '18 at 23:59

1 Answers1

-1

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.