iOS 8 Programming Fundamentals with Swift: Swift, Xcode, and Cocoa Basics by Matt Neuburg

iOS 8 Programming Fundamentals with Swift: Swift, Xcode, and Cocoa Basics by Matt Neuburg

Author:Matt Neuburg [Neuburg, Matt]
Language: eng
Format: epub, azw3, pdf
ISBN: 9781491908907
Publisher: O'Reilly Media
Published: 2015-03-12T22:00:00+00:00


Our app, however, is a Swift program. It has no main function! Instead, Swift has a special attribute: @UIApplicationMain. If you look in the AppDelegate.swift file, you can see it, attached to the declaration of the AppDelegate class:

@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {

This attribute essentially does everything that the Objective-C main.m file was doing: it creates an entry point that calls UIApplicationMain to get the app started.

Under certain circumstances, you might like to remove the @UIApplicationMain attribute and substitute a main file. You are free to do this. Your file can be an Objective-C file or a Swift file. Let’s say it’s to be a Swift file. You would create a main.swift file and make sure it is added to the app target. The name is crucial, because a file called main.swift gets a special dispensation: it is allowed to put executable code at the top level of the file. The file should contain essentially the Swift equivalent of the Objective-C call to UIApplicationMain, like this:

import UIKit UIApplicationMain( Process.argc, Process.unsafeArgv, nil, NSStringFromClass(AppDelegate))

Why might you do that sort of thing? Presumably, it would be because you want to do other things in the main.swift file, or because you want to customize the call to UIApplicationMain.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.