Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import Foundation
  2.  
  3. if let bundleURL = NSBundle.mainBundle().URLForResource("Settings", withExtension: "bundle") {
  4. NSUserDefaults.registerDefaults(settingsBundleURL: bundleURL)
  5. }
  6.  
  7. extension NSUserDefaults {
  8. static func registerDefaults(#settingsBundleURL: NSURL) {
  9. if let rootDict = NSDictionary(contentsOfURL: settingsBundleURL.URLByAppendingPathComponent("Root.plist")) {
  10. var defaults: NSUserDefaults?
  11. if let containerIdentifier = rootDict.valueForKey("ApplicationGroupContainerIdentifier") as? String {
  12. defaults = NSUserDefaults(suiteName: containerIdentifier)
  13. } else {
  14. defaults = NSUserDefaults.standardUserDefaults()
  15. }
  16. if let defaults = defaults, preferences = rootDict.valueForKey("PreferenceSpecifiers") as? [[String:AnyObject]] {
  17. var registrationDictionary: [NSObject:AnyObject] = [:]
  18. for prefs in preferences {
  19. if let key = prefs["Key"] as? String, let value = p["DefaultValue"] {
  20. registrationDictionary[key] = value
  21. }
  22. }
  23. defaults.registerDefaults(registrationDictionary)
  24. }
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement