Where Does a Swift iOS Application Begin Its Life

Where in my iOS (Swift) application lifecycle should i fetch all my data from firebase?

You should fetch your data in ViewDidLoad()

viewDidLoad()—Called when the view controller’s content view (the top of its view hierarchy) is created and loaded from a storyboard. The view controller’s outlets are guaranteed to have valid values by the time this method is called. Use this method to perform any additional setup required by your view controller.

Typically, iOS calls viewDidLoad() only once, when its content view is first created; however, the content view is not necessarily created when the controller is first instantiated. Instead, it is lazily created the first time the system or any code access the controller’s view property.

Your data will be fetched when you view in loaded.

If you want to refresh your data whenever your view gets diplayed then i use may use.

viewWillAppear()—Called just before the view controller’s content view is added to the app’s view hierarchy. Use this method to trigger any operations that need to occur before the content view is presented onscreen. Despite the name, just because the system calls this method, it does not guarantee that the content view will become visible. The view may be obscured by other views or hidden. This method simply indicates that the content view is about to be added to the app’s view hierarchy.

Is there any life-cycle graph for Swift look like same as we know for Objective-C?

It's the same because it's not a language depending life-cycle. It's an Application life-cycle.

You could change the language, but the way application works still be the same. If there were any differences, you won't be able to use swift/objc in the same project.

All calls are still there, but they change the way they look (but not named) a bit because of swift syntax. You could look them up here: Looking to understand the iOS UIViewController lifecycle

Which one of the App life cycle methods gets called when 3DTouch home screen quick actions are presented?

This is not possible, dynamic does not mean you can execute code at display of quick action. Your app can only setup dynamic quick actions after launch.

https://developer.apple.com/documentation/uikit/uiapplicationshortcutitem

Dynamic vs. Static Quick Actions
Although immutable, a UIApplicationShortcutItem instance is considered dynamic to distinguish it from a static quick action you specify at build time.
Define Home screen dynamic quick actions using this class. Your code creates dynamic quick actions, and registers them with your app object, at runtime.

Which method and function is called first when any iOS application start?

I suppose its

int main(int argc, char *argv[])

in main.m file

But for practical purposes I think you usually need to implement some of the UIApplicationDelegate's methods, depending on situation:

application:didFinishLaunchingWithOptions:
applicationDidBecomeActive:
applicationWillEnterForeground:

What does @UIApplicationMain mean?

The @UIApplicationMain attribute in Swift replaces the trivial main.m file found in Objective-C projects (whose purpose is to implement the main function that's the entry point for all C programs and call UIApplicationMain to kick off the Cocoa Touch run loop and app infrastructure).

In Objective-C, the main (heh) bit of per-app configuration that the UIApplicationMain function provides is designating one of your app's custom classes as the delegate of the shared UIApplication object. In Swift, you can easily designate this class by adding the @UIApplicationMain attribute to that class' declaration. (You can also still invoke the UIApplicationMain function directly if you have reason to. In Swift you put that call in top-level code in a main.swift file.)

@UIApplicationMain is for iOS only. In OS X, the app delegate is traditionally set in the main nib file designated by the Info.plist (the same for Swift as for ObjC) — but with OS X storyboards there's no main nib file, so @NSApplicationMain does the same thing there.

IOS application lifecycle: When are the view or view controllers called on application startup?

To be asking this is to misunderstand what AppDelegate is for. AppDelegate is there to receive important events in the application lifecycle, and for you to act on these events if you want. But these events are generated within the UIApplication code:

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/

A whole lot of framework code is included in your App but remains hidden (no source shown, all precompiled, automatically included libraries); you have to spend substantial time reading the Apple dev docs to understand your entry points.

Within Xcode, you set one View Controller as the "is initial view controller" attribute within the Attributes Inspector. The UIApplication startup code parses your Main.storyboard file, looks for this attribute, instantiates this view controller for you, and presents it for display as the root view controller by connecting it to the App's UIWindow. Then you are free to override any of the View Controller lifecycle events you need, implement as many @IBActions as you want, work with your @IBOutlets and in general go about your iOS-based event-driven programming.

Also, a ViewController manages a set of views (UIViews), but it is not a view itself.

Also, MVC is a repeating pattern within any GUI-based application; it is not the governing pattern, because it says nothing about how an App starts up and shuts down, which varies greatly between operating environments.

So it seems you're still in somewhat of a haze and need to do a lot of reading. It begs the question -- what are you really trying to do?



Related Topics



Leave a reply



Submit