Swift / Parse: Checking to make sure the data loaded - ios

Got an app written in Swift that creates a PFObject, saves it and then goes to another view controller. At that view controller, the data is read from Parse.com and displayed on the page. In the simulator and on my iPad Air 2, the app runs fine. On older iPads, however, it crashes at the new view controller. I think it's a simple matter of trying to show the data before it's loaded. I've put in a delay that stops the crash, but I'd like a more elegant solution.
I'd like to be able to check to see if the data is loaded (that's easy - if data != nil) but if it is nil, how do I get it to sit and wait for it to load? Any suggestions?
I'm a noob so feel free to talk slowly... ;)
Thanks!!!

Related

iOS SwiftUI widget issue, the widget load old/default data when is added to lockscreen / home on a physical device

forgive me if I say nonsense, I have been fiddling with swift for just over 2 months ...be patient :-)
So, I have a problem with the widget and I don't understand what it depends on, maybe it happened to someone and it could help me.
Everything works perfectly, app and widget update, except one (damned) thing: when I add the widget from the gallery for the first time, it loads me the default data.
Let me explain: when selecting from the widget gallery the snapshots are updated correctly; when I select it it flashes on an old view (something I would say imperceptible even if it bothers me personally) and then, no one knows why, it loads the default data when it is added to the home / lockscreen, as if the userdefaults were empty .
On the simulator it loads it well, on my device it doesn't (iPhone 7).
I would like to understand, from you who know more than me, how the views are divided at the juncture of the gallery:
from what I understand, when I see the preview from the gallery it is the getSnapshot: in that context, I load the data from the Userdefaults store to get an updated preview; the same goes for the placeholder since I don't have to fetch anything and therefore I should have the result immediately (but I didn't really understand where the placeholder would appear .. maybe it's that flash I hate so much?).
in getTimeline I do the same, I load the data from the store and then in the for of the timeline I recall them.
has it ever happened to anyone?
I would like to post code but I do not have the possibility for various reasons .. i'm really sorry.
thank you very much to those who will try to help me!

Complex Startup Logic in iOS Apps: Where Should it Reside?

Everyone has seen the classic didFinishLaunchingMethod run amok.
Well now that we have additional things to consult when starting up like CloudKit, that are, to make things worse, asynchronous, the app delegate seems like the wrong place to do even the most basic stuff like asking if they have accounts and establishing syncing, or grabbing a snapshot.
I hate the idea that those things would go into the first controller that the app would launch, flashes me back to 4GL tinkertoys from days of yore.
Yet, we have to honor the flows of the storyboards. I have found nothing searching around on this. And sadly the most extensive Apple example, Lister, is not a great source for best practices.
It's suitable for the app delegate to trigger the start of this work, but not to handle the results. Often you want some way to display progress / errors / request user info. So, having some form of 'splash' view controller which handles the transition from your launch image into this process and controls the flow into the main app is handy. Generally the logic for this kind of thing is reusable in other situations so that part should be in some other controller class. The storyboard can make the splash VC the initial controller and the app delegate can create and pass it the data controller class which deals with the logic and updates the VC (it's delegate) with the results. Often the splash VC will then pass the data controller on to the subsequent VC it displays, though that isn't required of course.

TodayViewController recreated every time Notification Center is shown

When trying to develop a Today Extension for iOS 8 I found a weird issue. It would seem that the View Controller I'm using is being recreated every time the user opens Notification Center. This means that there is no data retention and hence no way for me to know if the extension needs to update or not.
The main reason for wanting to do this is that I want to preserve the height of the widget (Using preferredContentSize). The problem is that when the view loads this value always gets reset which leads to the widget jumping around in size. The Stocks widget is an example of how it's supposed to work and they've obviously solved it so there has to be some way of retaining the data between different "sessions". I can also tell from the debugger that the process continues to run, so it's just down to something in Apple's code forcing the View Controller to be recreated.
My question is, is this a bug? Or is it based on some setting or some property that I'm missing? Or is it maybe just the way it's supposed to work? If so, what is the workaround?
That's the way they work. Save your information to the device so you can reload it the next time you launch, along with the update time so you know if it's out of date. For small amounts of data, just use NSUserDefaults. For larger amounts save to a file, CoreData, sqlite, etc.

closing out modal view completely ios

I have a messaging system, theres a inbox view and a viewmessage view, if i go back to the inbox im still reciving data from that message, and if i load another conversation between me ad another user its still loading the previous conversation data i had (verified by logging the convo's, and the new one i have open, and its a continuous loop so to say... basically im trying to figure out how to totally close out a view... i seen dissmissViewController and used that, but all it does is visually make the view go away... it doesn't truly close it.. whats the method to call to do what im trying to achieve?
These are all modal views, my app uses no navigation views due to the nature of the app
edit: i found some great documentation that im going to look over hopefully i'll get my answer from there.
Using Delegation to Communicate with Other Controllers

can my app delegate be used as a controller of UIViewControllers (MVC)

Can an app delegate act the as the glue between all my UIViewControllers for the whole app?
I'm creating a mail client that has a navigation structure very much like sparrow (and fb etc). The first screen would be a login screen.. which would then lead to a UITableViewController that has the famous left menu button, which if clicked reveales other VC's underneath.
To make a long story short, right now it's my app delegate that's running the show.. it's the one that decides if to show the login screen if on first visit, or the default mailbox along with its subviews. If I get information from one subview, it hands off that info to the app delegate, which in turn passes it on to other view controllers.
Is this right from an MVC point of view? I know an app delegate is the first point of contact, it's what kicks off the application, but I haven't seen it used this extensively. I just want to make sure if I'm following iOS MVC best practices here.
It's not recommended, but it's perfectly legal to do that. I generally use a master view controller class and do most of the heavy lifting in that. Keep in mind that XCode will dump most of the auto generated code in the app delegate if you are using Core Data, so it can get a little difficult to navigate if you are using Core Data. It's really just a personal preference though. If it were me, I would still have the app delegate do the login screen vs. main screen logic, but put most of the app logic in a main screen controller.

Resources