Use of the Settings.bundle in Chapter 2: Introducing App Search

Hi.

This went right over my head. You need to get at the SearchIndexingPreference and this is in the Root.plist of the Settings.bundle. How did swift know to get it from the Settings.bundle without parsing the Root.plist? You just went and grabbed it out of there using the Identifier field:

struct Setting {
static var searchIndexingPreference: SearchIndexingPreference {
let preferenceRawValue = NSUserDefaults.standardUserDefaults().integerForKey(“SearchIndexingPreference”)
if let preference = SearchIndexingPreference(rawValue: preferenceRawValue) {
return preference
} else {
return .Disabled
}
}
}

Tell me what is the subtlety about NSUserDefaults I’m missing!

In Objective-C, this is always hairy to get the dictionary of PreferenceSpecifiers and then the array within of pref/type pairs, of which there may be a default. Although, if I try doing that from swift, even using NSDictionary and NSArray, etc. it dies a bad death (I have also filed a bug on this issue.)

-Paul