Skip to Content
Programming iOS 10
book

Programming iOS 10

by Matt Neuburg
November 2016
Beginner to intermediate content levelBeginner to intermediate
800 pages
30h 12m
English
O'Reilly Media, Inc.
Content preview from Programming iOS 10

Appendix B. Some Useful Utility Functions

As you work with iOS and Swift, you’ll doubtless develop a personal library of frequently used convenience functions. Here are some of mine. Every one of them has come in handy in my own life; I keep them available as user snippets in Xcode so that I can paste them into any project.

Launch Without Main Storyboard

As I explained in Chapter 1, if an app lacks a main storyboard, or if you want to ignore the main storyboard and generate the app’s initial interface yourself, configuring the window and supplying the root view controller is up to you. A minimal app delegate class would look something like this:

@UIApplicationMain
class AppDelegate : UIResponder, UIApplicationDelegate {
    var window : UIWindow?
    func application(_ application: UIApplication,
        didFinishLaunchingWithOptions
        launchOptions: [UIApplicationLaunchOptionsKey : Any]?)
        -> Bool {
            self.window = self.window ?? UIWindow()
            self.window!.backgroundColor = .white
            self.window!.rootViewController = ViewController()
            self.window!.makeKeyAndVisible()
            return true
    }
}

Core Graphics Initializers

C and Objective-C have the Core Graphics CGRectMake function, which needs no argument labels when you call it. Infuriatingly, Swift 3 cuts off access to this function, leaving only the various CGRect initializers, all of which do need argument labels. I find those labels otiose, clumsy, and verbose; we know what each argument signifies, so why clutter the call with labels? The solution is another ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming iOS 12

Programming iOS 12

Matt Neuburg
Programming iOS 11

Programming iOS 11

Matt Neuburg
Programming iOS 13

Programming iOS 13

Matt Neuburg

Publisher Resources

ISBN: 9781491970157Errata Page