5

I attempting to grasp some kind of unit tests, so we create mock user defaults.

class MockUserDefaults: UserDefaults {
var gameStyleChanged = 0
override func set(_ value: Int, forKey defaultName: String) {
if defaultName == "something" {
  someStyleChanged += 1
}
}
} 

right after in setup() i create

mockUserDefaults = MockUserDefaults(suiteName: "testing")! 

So i confused i can't understand full meaning of suiteName i've read official documentation but it is not clear enough, please help

Ninja
  • 309
  • 7
  • 26
  • 1
    you can create your own domain what you may use in your other apps or app-extentions (a.k.a. in your own _app-group_) to share data between them flawlessly. ([_source_](https://developer.apple.com/documentation/foundation/userdefaults/1409957-init)). – holex Nov 16 '17 at 11:17

1 Answers1

7

suiteName:is kind of an identifier which helps you create preferences(UserDefaults) store. By using a particular suiteName, you are creating a preferences store, that is not bounded to a particular application (whereas standard UserDefaults are different for every application). Because of this reason, you can create a store, that can be shared between different app/extensions.

Puneet Sharma
  • 9,369
  • 1
  • 27
  • 33