![]() |
||
---|---|---|
.github | ||
DemoApp | ||
MockUserDefaults.xcodeproj | ||
Sources/MockUserDefaults | ||
Tests | ||
fastlane | ||
scripts | ||
.gitignore | ||
.ruby-version | ||
Gemfile | ||
Gemfile.lock | ||
LICENSE | ||
Makefile | ||
MockUserDefaults.podspec | ||
Package.swift | ||
README.md | ||
versions.json |
README.md
MockUserDefaults
MockUserDefaults
is a simple replacement for NSUserDefaults
/UserDefaults
to make test easier.
Installation
SwiftPM (recommended)
.package(url: "https://github.com/417-72KI/MockUserDefaults.git", from: "1.3.1"),
CocoaPods
pod 'MockUserDefaults'
Carthage (deprecated, will drop support in 2.0.0)
github "417-72KI/MockUserDefaults"
Usage
Objective-C
NSUserDefaults *userDefaults = [NSUserDefaults mockedUserDefaults];
[userDefaults setObject:@"string" forKey:@"key"];
XCTAssertEqualObjects([userDefaults objectForKey:@"key"], @"string");
Swift
let userDefaults: UserDefaults = .mocked
userDefaults.set("string", forKey: "key")
XCTAssertEqual(userDefaults.string(forKey: "key"), "string")
Demo
Dependencies
Tool
- CocoaPods
- Bundler
- Carthage
- Homebrew
- XcodeGen
- Mint
- Homebrew
- Mint
- Fastlane
- Bundler
Library
- R.swift
- RxSwift
- RxDataSources
- Nimble
- Quick
Create project
First time
make init_demo_app
After the first time
make demo_app
Usage
- open
MockUserDefaultsDemo.xcworkspace
- Build and run app (⌘+R) in iPhone / iPad Simulator
- Add any keys and values
- Run test (⌘+U) in same simulator
- Re-run app (⌘+R) in same simulator
- You can see that the app isn't affected by the test.