Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- if let bundleURL = NSBundle.mainBundle().URLForResource("Settings", withExtension: "bundle") {
- NSUserDefaults.registerDefaults(settingsBundleURL: bundleURL)
- }
- extension NSUserDefaults {
- static func registerDefaults(#settingsBundleURL: NSURL) {
- if let rootDict = NSDictionary(contentsOfURL: settingsBundleURL.URLByAppendingPathComponent("Root.plist")) {
- var defaults: NSUserDefaults?
- if let containerIdentifier = rootDict.valueForKey("ApplicationGroupContainerIdentifier") as? String {
- defaults = NSUserDefaults(suiteName: containerIdentifier)
- } else {
- defaults = NSUserDefaults.standardUserDefaults()
- }
- if let defaults = defaults, preferences = rootDict.valueForKey("PreferenceSpecifiers") as? [[String:AnyObject]] {
- var registrationDictionary: [NSObject:AnyObject] = [:]
- for prefs in preferences {
- if let key = prefs["Key"] as? String, let value = p["DefaultValue"] {
- registrationDictionary[key] = value
- }
- }
- defaults.registerDefaults(registrationDictionary)
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement