Schrodinger's bit
Schrodinger's bit

Reputation: 33

Problems understanding on of the Swift method parameters

In the following method what is launchOptions in the parameter declaration? Is it an optional of an array of type NSObject? I am fairly new to swift so it might sound silly, but I don't get what does didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]? mean. Any help is much appreciated :)

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    self.window = UIWindow(frame:UIScreen.mainScreen().bounds)
    self.window!.backgroundColor = UIColor.whiteColor()
    self.window!.makeKeyAndVisible()
    return true
}

Upvotes: 0

Views: 136

Answers (2)

agy
agy

Reputation: 2854

This is the way swift translates a NSArray.

Swift bridges between the Array type and the NSArray class. When you bridge from an NSArray object to a Swift array, the resulting array is of type [AnyObject]. An object is AnyObject compatible if it is an instance of an Objective-C or Swift class, or if the object can be bridged to one. You can bridge any NSArray object to a Swift array because all Objective-C objects are AnyObject compatible. Because all NSArray objects can be bridged to Swift arrays, the Swift compiler replaces the NSArray class with [AnyObject] when it imports Objective-C APIs

here you can find more about Cocoa data types

Upvotes: 1

matthias
matthias

Reputation: 947

A dictionary indicating the reason the app was launched (if any). The contents of this dictionary may be empty in situations where the user launched the app directly. For information about the possible keys in this dictionary and how to handle them, see Launch Options Keys.

From Apple Docs https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/#//apple_ref/occ/intfm/UIApplicationDelegate/application:didFinishLaunchingWithOptions:

Possible Keys:

UIApplicationLaunchOptionsURLKey: String UIApplicationLaunchOptionsSourceApplicationKey: String UIApplicationLaunchOptionsRemoteNotificationKey: String UIApplicationLaunchOptionsAnnotationKey: String UIApplicationLaunchOptionsLocalNotificationKey: String UIApplicationLaunchOptionsLocationKey: String UIApplicationLaunchOptionsNewsstandDownloadsKey: String UIApplicationLaunchOptionsBluetoothCentralsKey: String UIApplicationLaunchOptionsBluetoothPeripheralsKey: String UIApplicationLaunchOptionsUserActivityDictionaryKey: String UIApplicationLaunchOptionsUserActivityTypeKey: String

and explanation: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/#//apple_ref/doc/constant_group/Launch_Options_Keys

Upvotes: 0

Related Questions